我有一个带有以下 ajax 方法的 html 页面:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
这是返回给我的 403 禁止。一位同事构建了 Web 服务,我无法访问代码,也无法在他休假时更改它。我需要显示这些数据——此时我尝试的一切都失败了,并给了我一个 403 禁止错误。为了显示代码,我已将 url 名称和成功函数更改为警报对话框。
另一件事是 json 似乎被包装在 XML 中,来自一个看起来像这样的 ASP.NET 网络服务:
<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>
这不是最初的意图,因为我期望接收 json 但是我现在对此无能为力,必须用 XML 处理它,然后尝试将内部格式化的 json 转换为 json 对象。
我也尝试过以下方法:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "xml",
contentType: "text/xml",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
最后,我将在此处为我尝试过的两个示例输出 FireFox 的 Firebug 响应(json/xml)
json:http: //i.imgur.com/zJy4BvD.jpg
XML:http: //i.imgur.com/6qiGVwQ.jpg
非常感谢您的阅读!