AJAX data representations... JSON, Text, XML
Greetings,
I've been playing with this and got it to work, but it just isn't satisfactory.
I use JQuery AJAX to call a Web Method in C#. Right now I have the datatype: text.
With it set to text, I can return from C# - strReturn = "{\"error\":\"No Data sent\"}"; and I can my message (a little more than just the ("error") with
var obj = jQuery.parseJSON(msg);
var obj1 = jQuery.parseJSON(obj.d);
alert("onSuccess -\nerror=" + obj1.error + "...\nDate=" + obj1.date + "\n...Table=" + obj1.contacttable + "...");
OK, first... I think what I sent is good, "{\"error\":\"No Data sent\"}"; , but there cannot be any double quotes (") in the data parts, even escaped, and converting them to single quotes (') can be an issue. I can live with that part if I have to.
Much more importantly, if I change to dataType: "json", the message comes back from AJAX as an object but
var obj1 = jQuery.parseJSON(msg); I get the message
SyntaxError:JSON.parse:unexpected character
Now I don't get this with datatype:text and I have tried a huge number of variations, but it no workum.
Sew, I would like (1) any suggestions, (2) any example JSON string that will work under these conditions (preferably 2 pieces of data to be parsed), (3) a short XML string with two data members that will work also, as I want to make it work with that next.
If you have any comments about dealing with quotes on both sides of the pipeline (why I want to try XML) I would appreciate that as well.
Thank you much, Mike