【发布时间】:2011-05-24 23:10:26
【问题描述】:
我想使用 jquery 从客户端使用跨域 Web 服务
function TestService() {
$.ajax({
url: "http://service.asmx/GetGeoCompletionList",
data: { "prefixText":"eka", "count":"10", "contextKey":"Trace_0$Rus" },
dataType: "jsonp",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.statusText);
}
});
}
在错误处理程序中,我有:
textStatus=parseerror
XMLHttpRequest 的状态为 200 和 readyState 4
errorThrown 是jQuery16103495572647140...78197139 was not called
我已经花了很多时间在它上面,但无法让它工作。你能帮帮我吗?
更新
谢谢,我改用 GET,并修复我的数据字符串。
服务返回有效的 JSON 对象。我可以在使用此服务的其他站点上的 firebug 上看到它。但是该站点正在获取通用 json(因为它有一个域)。
那么,如果网络服务返回有效的 JSON(不是 jsonp),我不能对 jsonp 使用相同的方法吗?使用其他域的 json web-service 可以做什么?
【问题讨论】:
-
HTTP 请求和 HTTP 响应是什么样的?
-
如果您不明白为什么如果它只返回 JSON 而不是 JSONP 就不能使用该服务,请阅读此处:stackoverflow.com/questions/2067472/please-explain-jsonp/…
标签: javascript jquery asp.net web-services