我創建了一個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