我正在尝试从给定的ajax调用中调用webservice方法。我的web服务托管在同一个应用程序中。
$.ajax({
type: "POST",
url: "http://1.1.1.1/demo/sblead.asmx/SBLeadsSave",
data: "{'whenNeeded':'" + whenNeeded + "','howLong': '" + howLong + "','size': '" + Size + "','customerName': '" + name + "','mobile': '" + mobile + "','email': '" + email + "','comments': '" + comments + "','nextContract': '','unitLocation': '" + unitLocation + "'}",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
callback: '?',
crossDomain: true,
success: function (response) {
// debugger;
var res = response.d;
if (res == "True") {
location.href = "http://1.1.1.1/SBleadSuccess.htm";
} else {
alert('Data Saving failed please try again');
}
},
failure: function (result) {
alert(result.status + ' ' + result.statusText);
},
beforeSend: setHeader网络服务方法没有被调用,当我使用Chrome开发人员工具-->网络看到它时,我可以看到响应,因为访问控制允许源http://www.example.com是不允许的。
它可以在测试服务器上运行,但不能在生产服务器上运行。
我怎样才能解决这个问题?
发布于 2012-09-27 21:10:04
您需要在响应头中允许您的生产服务器:
Access-Control-Allow-Origin: <production origin> | *你可以在MDN: HTTP access control (CORS)上看到更多信息。
发布于 2012-09-27 21:10:52
这是因为您正在调用http://1.1.1.1/demo/sblead.asmx/SBLeadsSave,但这并不是您的生产服务器位置。
输入您的生产服务器位置,或直接输入/demo/sblead.asmx/SBLeadsSave。
https://stackoverflow.com/questions/12622104
复制相似问题