我在.asmx文件中创建一个Web方法,并将其托管在服务器上,当我从任何远程应用程序调用它时,我收到此错误:
detailed error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.200.55/ChatApp.asmx/UserLogin. This can be fixed by moving the resource to the same domain or enabling CORS.
我的WebMethod .cs代码如下:
[WebMethod]
public string UserLogin(string u_name,string user_pwd)
{
string result = "true";
if (u_name == "unicolumn" && user_pwd=="admin")
{
result = "true";
}
else
{
result = "false";
}
return result;
}
我的ajax调用方法在这里:
function apiLogin()
{
debugger;
var UserName = document.getElementById('txtUserName').value;
var PWD = document.getElementById('txtUserPWD').value;
$.ajax({
type: "POST",
url: "http://192.168.200.55/ChatApp.asmx/UserLogin",
data: "{'u_name':'" + UserName + "','user_pwd':'" + PWD + "'}", //{u_name:UserName,user_pwd:PWD},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
},
failure: function(Response) {
alert(Response.d);
}
});
}
当我通过运行visual studio应用程序对其进行测试时,它正常工作,以防从另一个应用程序调用它,生成与跨源请求被阻止相关的错误。 有人可以帮我弄清楚我在这里失踪了什么......先谢谢。