0
我試圖調用使用AJAXWCF服務,下面是我的代碼:我怎樣才能解決這個錯誤
$.ajax({
url: "http://localhost/TestingServices/Service1.svc/GetData"
data: "{'value:1}",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
但在運行後它給了我以下錯誤:
XMLHttpRequest cannot load
http://localhost/TestingServices/Service1.svc/GetData.Response to
preflight request doesn't pass access control check:
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 404.
燦任何人都可以幫我解決這個問題?
刪除的contentType:「應用/ JSON的;字符集= UTF-8 「然後嘗試,,, –
請參閱http://stackoverflow.com/questions/33820142/getting-request-doesnt-pass-access-control-check-no-access-control-allow-orig – RRR
現在,我得到dis錯誤:POST http://localhost/Wcf/service1.svc/GetData 415(無法處理消息,因爲內容t type'application/x-www-form-urlencoded; charset = UTF-8'不是預期的類型'text/xml;字符集= UTF-8' )。 – tiya