我有来自 ASP.NET Web 服务的响应
<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>
使用此 jquery 函数调用它:
$(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));
}
});
});
我的第一个问题是,我有 403 个禁止使用此功能的问题,但省略 contentType 改变了这一点。然后我遇到了 XML 解析问题,一时兴起将 dataType 更改为脚本修复了该问题并给了我一个响应,然后我点击了成功功能。为什么这行得通?
我也想知道如何打印出这些数据,因为试图将其视为 json 是行不通的,XML 也行不通。
在 chrome 中,我收到此警告:
Resource interpreted as Script but transferred with MIME type text/xml: "http://www.webservice.com/blahblah.asmx/blahb123?tnWsGuid=TEST1&_=1366025879568."
附加到此网址末尾的部分让我感到困惑(在 TEST1 之后)。在控制台中,我也在 chrome 中收到此错误:
Uncaught SyntaxError: Unexpected token <
Firebug 给了我:
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>
所以基本上现在 dataType 是脚本,我得到了某种响应,但仍然不知道如何解析这些数据。最好变成一个html表格。
我希望你能帮忙!谢谢阅读!
编辑:
这是 Firebug在此处记录的标头信息的链接