调用跨域 Web 服务时获取 HTTP 302 状态代码?
我使用 jQuery 调用跨域 Web 服务。来自本地主机的 Web 服务调用成功完成,而从其他域调用时,我收到 HTTP 302 状态代码错误。
这是网络服务调用;
$.ajax({
type: "POST",
url: "http://wthdevsr01:45452/webservices/GetUserAcceptancePolicyStatus.asmx/GetAcceptancePolicyReadStatus",
data: '{"userID" : \"' + $.trim(userID) + '\", "documentID" : \"' + $.trim(documentID) + '\"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
if (result.d != '') {
if (result.d == '1') {
alert("ACCEPTED");
}
else if (result.d == '0') {
alert("NOT ACCEPTED");
}
else {
alert(result.d);
}
}
},
error:function (result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
});
我想知道问题出在哪里?有什么想法吗?
I use jQuery to call a cross domain web service. Web service call from local host completed successfully, while calling from other domains, I got HTTP 302 status code error.
Here is web service call;
$.ajax({
type: "POST",
url: "http://wthdevsr01:45452/webservices/GetUserAcceptancePolicyStatus.asmx/GetAcceptancePolicyReadStatus",
data: '{"userID" : \"' + $.trim(userID) + '\", "documentID" : \"' + $.trim(documentID) + '\"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
if (result.d != '') {
if (result.d == '1') {
alert("ACCEPTED");
}
else if (result.d == '0') {
alert("NOT ACCEPTED");
}
else {
alert(result.d);
}
}
},
error:function (result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
});
I wonder where is the problem? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是由于 JavaScript 同源策略:http://en.wikipedia.org/wiki/Same_origin_policy
您可能需要在同一域上使用服务器端代理,或使用类似 http:// www.ajax-cross-domain.com/
Probably due to the JavaScript Same Origin Policy: http://en.wikipedia.org/wiki/Same_origin_policy
You may need to use a server-side proxy on the same domain, or use something like http://www.ajax-cross-domain.com/