I have this response coming from a ASP.NET web service
<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>
which is being called with this jquery function:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "script",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
My first question is this, I was having 403 forbidden issues with this function but omitting the contentType changed that. Then I was getting XML parsing issue and on a whim changing the dataType to script fixed that and gave me a response and I hit the success function. Why did that work?
I also would like to know how I can print out this data, because trying to treat it as json won't work, neither does XML.
In chrome I receive this warning:
Resource interpreted as Script but transferred with MIME type text/xml: "http://www.webservice.com/blahblah.asmx/blahb123?tnWsGuid=TEST1&_=1366025879568."
The part appended to the end of this url is confusing me (after TEST1). In the console I also get this error in chrome:
Uncaught SyntaxError: Unexpected token <
Firebug gives me:
SyntaxError: syntax error
[Break On This Error]
<?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>
So basically now that the dataType is script I get some sort of response but still have no idea how to parse this data. Preferably into a html table.
I hope you can help! Thanks for reading!
Edit:
Here is a link to the header information logged by Firebug here
your need to set datatype to json as the server send a json array. see the datatype section here http://api.jquery.com/jQuery.ajax/
我已经解决了这个问题,并成功地在IE中返回了数据集(由于Chrome和Firefox的异步问题,目前还不能在Chrome和Firefox上运行,我希望在托管此页面时可以解决这两个问题。我添加了$.support.cors = true;
就在ajax函数和我的新成功函数之前,正确地显示了数据,如下所示:
function(data, status, jqxhr) { xmlString = data;
alert(xmlString); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.