I have a jquery function which communicates with an ASP.NET web service which looks like this
$(document).ready(function() {
$.support.cors = true;
$.ajax({
type: "GET",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "text",
success: function(data, status, jqxhr) {
xmlString = data;
alert(xmlString);
},
error: function (request, status, error) {
alert(status);
}
});
});
Alert display's this:
<?xml version="1.0" encoding = "utf-8"?>
<string xmlns = "http://Walkthrough/XmlWebServices/">
{"approverName":"","emailAddress":"","companyName":"ABC","address":{"streetAddress1":"12 BlahBlah","streetAddress2":"","state":"ON","zipCode":"","country":"SO","phoneNumber":""},"tabledata:"[{"vendorPart":"AAAAA","partDescription":"N/A","price":"0.00","quantity":"28"},{"vendorPart":"BBBBBBB","partDescription":"N/A","price":"0.00","quantity":"3"},{"vendorPart":"CCCCCC","partDescription":"N/A","price":"0.00","quantity":"25"}]}
</string>
My dataType is now text. I know how to parse JSON however, now what I need to do is somehow access the JSON embedded in the XML envelope and turn it into a JSON object so I can use JQuery to parse it.
Here is what I have tried in the $.ajax function:
success: function(data, status, jqxhr) {
xmlString = data;
var jsondata = jQuery.parseJSON(xmlString.substr(xmlString.indexOf('{')));
alert(jsondata);
}
But was returned with an error of Invalid character which in the IE debugger look's like this
Any idea how I can access the data inside the xml envelope and turn it into a JSON object so I can parse it as JSON? I do not have the ability to change the web service so this must all be done within the web page.
$.support.cors = truedoesn't actually do anything unless the current browser supports CORS and jQuery incorrectly detects that it doesn't.