我尝试使用 jsonp 激活 jQuery.ajax() 请求,但收到以下错误:
Resource interpreted as Script but transferred with MIME type text/xml
我的要求是:
return $.ajax({
type: 'GET',
url: this.AgentServiceUrl + "/" + methodName,
async: false,
jsonpCallback: 'jsonCallback',
contentType: "text/xml",
dataType: 'jsonp',
success: function (json) {
console.dir(json.sites);
},
error: function (e) {
console.log(e.message);
}
});
我从服务器得到的响应是:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 114
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 19 Jun 2013 08:43:13 GMT
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://CosmoCom.com/WebServices/TCWS/Agent">010001</string>
我能做什么?
最佳答案
正如错误消息正确所述,当您将数据类型标记为 jsonp 时。这意味着您将收到的数据将是脚本。所以你不能将你的内容类型设置为“text/xml”。 尝试将其更改为 "application/json" 。
还要确保您的服务启用了 jsonp,这意味着它返回包装在回调函数中的数据。
关于ajax - 尝试使用 jQuery.ajax 和 jsonp 获取 xml 服务器响应时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17186802/