我创建了一个REST
服务,我测试它在Chrome REST Console
。它的工作正常,我得到的响应,但同时通过jquery Ajax我得到"NetworkError: 405 Method Not Allowed error in Ajax Call
和Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:64132/Auth. (Reason: CORS request failed).
error.Here是我的Ajax代码..“NetworkError:405方法不允许在Ajax调用中的错误
var UserDetails = { "UserName": "Bond", "Password": "password" };
$.ajax({
type: 'POST',
url: 'http://localhost:64132/Auth',
crossDomain: true,
data: UserDetails,
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data.UserName);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("some error");
}
});
请帮我纠正这一点,并成功地调用Service.Thanks ..
更新
当我试图ŧ O调用从Chrome中的服务我收到以下错误控制台..
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Test.html:1 XMLHttpRequest cannot load http://localhost:64132/Auth. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405.
https://developer.mozilla.org/en-US/docs/Web/HTTP/ Access_control_CORS – Eric
您在服务器端使用的是什么 –
'type:'POST','尝试'type:'GET',' – Jai