I have the following jQuery code:
$.ajax({ type: "POST", url: "Services/MyService.asmx/Select", dataType: "json", data: "{'data':'test'}", contentType: "application/json; charset=utf-8", success: function(msg){ alert(msg); }, error: function(xhr){ alert(xhr.statusText);} });
A method call returns the following:
"{"FirstName":"James"}"
When I return my value, my warning returns the full json string. If I try to alert(msg.FirstName) , I get "undefined".
I have seen many examples using the getJSON () method; however, I have not seen a way to use this for the POST verb. Can someone point me in the right direction where I am going wrong? Based on the jquery documentation, the return value should be the same dataType (json) type, so I'm not sure what I am missing.
EDIT: I looked at my service, and these are comparable examples that I find in terms of the signature of the method returning the string. I also confirmed that the response type is / json application.
EDIT2: Updated answer to include external quotes. I also use my own JavaScriptConverter to serialize JSON. A custom converter simply takes my object properties (in this case, FirstName) and loads it, and it adds it to a set of dictionaries that ASP.Net AJAX Extensions v1.0 can easily serialize.
EDIT3: Studying the problem I ran into eval () (it caused the Expected ";" error), I noticed that json property names were also enclosed in quotation marks. As soon as I removed the quotation marks from the property name (not the value), eval () worked again. Now look at the server problem.
source share