我使用 chrome 尝试访问我的本地服务器。还使用 jquery-2.0.3 和 jquery-mobile-1.4.0-rc。我的页面网址是:file:///C:/Users/....../index.html
我的代码如下所示:
var login = {
in: function(){
var ajaxUrl = "http:// localhost/Account/Login/";
var loginModel = {
UserName: $("#userMame").val(),
Password: $("#password").val(),
RememberMe: true
};
$.mobile.loading('show');
$.ajax({
type: "POST",
url: ajaxUrl,
dataType: 'json',
data: JSON.stringify(loginModel),
contentType: "application/json;charset=windows-1255",
scriptCharset: "windows-1255",
headers : {Accept : "application/json",
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods": "POST,GET",
"Access-Control-Allow-Headers": "X-Authorization,X-Requested-With"},
crossDomain : true,
success: login.inSuccess,
error: login.inFailure
});
},
inSuccess: function(obj) {
alert("Success");
},
inFailure: function(obj, b, c) {
alert("Failure");
}
}
$(document).bind('pageinit', function () {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
调用 login.in() 时,我不断收到相同的错误:
OPTIONS http://localhost/Account/Login/ Origin null 是 Access-Control-Allow-Origin 不允许的。
如您所见,我已经尝试了所有方法。. .