1

I'm using jqplot to generate charts. It works fine when I define the source data in javascript:

  var goog2 = [["6/22/2009", 425.32],["6/8/2009", 424.84],["5/26/2009", 417.23]];

I'm now trying to pull the data from a server side web method:

  <WebMethod()> _
Public Shared Function Test() As String
    Return ("[[""6/22/2009"",425.32],[""7/22/2009"",429.32]];")
End Function

No matter what I do to the returned object I can't seem to get it into the format that's required.

   function DoAction2(cat) {
          $.ajax({
              type: "POST",
              url: "AjaxTest.aspx/Test",
              data: "{cat:" + cat + "}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(msg) {
              alert(msg.d);
                  var d = msg.d;
                  plot = $.jqplot('chart1', [d])

Any help would be appreciated.

2 Answers 2

1

Is the returned string from your Test() function the entire response?

In your JS you're asking for msg.d, but there's no d element in your JSON structure (as shown).

Also, the trailing semicolon shouldn't be there. It's not valid JSON.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes the returned string is the entire response. If I drop the semi colon, will the returned object be treated the same as the javascript variable declared client side to test?
Yes, it should be, but you just want msg, not msg.d.
thanks, I've changed it to msg and [[6/22/2009,425.32],[7/22/2009,429.32]] server side but get an error saying theres no data to plot
You took out the quote marks? (they are needed for the date fields)
0

It seems to me you're returning the exact structure you need from the server, yes? If so, then I don't understand your attempt to access 'msg.d' in your success function. 'msg' is your data structure...

Also, I have no idea what lang you're using on the server side so I don't know much about its syntax, but that does not appear to be properly escaping quotes/etc in order to produce a valid JSON response.

1 Comment

In some languages (particular those with a BASIC heritage) you have to use a pair of double quotes to obtain one double quote inside a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.