Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery and parsing JSON in the callback
    text
    copied!<p>I'm using jQuery to call an asmx and return some data. I'm making the call like this</p> <pre><code>function getRequestInfo(event) { var id = $('#&lt;%= RequestDaysId.ClientID %&gt;').val(); var formattedId = "{'id': '115'}"; $.ajax({ type: "Post", url: "services/VacationServices.asmx/GetVacationInfo", data: "{'id': '" + id + "'}", dataType: "json", contentType: "application/json; charset=utf-8", processdata: true, success: function(data) { $('#&lt;%=Note.ClientID %&gt;').val(data.Note); $('.pendingrequestinfo').show().fadeIn(2000); }, error: function(result, errortype, exceptionobject) { $('.failureMessage').fadeIn(2000).fadeOut(2000); } }) }; </code></pre> <p>Everything seems to be working fine, I set a break point in my success function and inspect the data object and see this. </p> <pre><code>"{"Note":"this is a note","dayInfo":[{"ShortDate":"3/4/2010","DayType":"Vacation","HalfDay":""},{"ShortDate":"3/5/2010","DayType":"Vacation","HalfDay":""}]}" </code></pre> <p>The problem comes when I try to get the values out of the JSON. If I do something like data.Note, I get undefined back. </p> <p>It's late, It's Saturday and I've been at it all day, I sure would like a push in the right direction when it comes to parsing though my JSON. </p> <p>EDIT: I'm using Asp.net and JavaScriptSerializer.Serialize() to create the JSON. When I set a break point and inspect the 'data' object it looks to have a property d that contains the string that should be JSON. </p> <p>ANOTHER EDIT: If I do something like this in my success </p> <pre><code>$('#&lt;%=Note.ClientID %&gt;').val(data.d.[0]); </code></pre> <p>I get the { opening curly brace. I guess i'm getting a string instead of JSON, but it seems to go against what the jquery api states about the return value when the datatype is set to JSON. </p> <p>Thanks guys. Jim</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload