我想運行我的phonegap應用程序在漣漪模擬器和調用方法從webservice.asmx在jQuery中使用ajax方法,但得到了Cors錯誤:在服務器端沒有'訪問控制允許來源'標題存在於所請求的資源ajax jquery phonegap
XMLHttpRequest cannot load https:\rippleapi.herokuapp.com\xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//www.my-domain.com/WebService.asmx/selectData. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:\localhost:4400' is therefore not allowed access. The response had HTTP status code 503.
- 已經放棄CORS(web.config中):
<system.webServer> <defaultDocument> <files> <clear /> <add value="index.aspx" /> <add value="WebService.asmx"/> </files> </defaultDocument> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*"/> <add name="Access-Control-Allow-Headers" value="Content-Type"/> </customHeaders> </httpProtocol> </system.webServer> <system.web> <webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices> <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> </system.web> <system.serviceModel>
我的AJAX方法:
$阿賈克斯({
類型: 「POST」,
跨域:真實,
網址: 「http://www.my-domain.com/WebService.asmx/selectData」,
數據:JSON.stringify(campaignData),
contentType:「application/json;字符集= UTF-8" ,
數據類型: 「JSON」,
成功:函數(MSG)
{
變種響應= msg.d;
變種resultLoop = $ parseJSON(響應);
控制檯.LOG(響應)
},
錯誤:功能(XHR,ajaxOptions,thrownError)
{
$ .mobile.loading( '隱藏');
警報( 「狀態:」 + xhr.status + 「thrownError:」+ thrownError +「ajaxOption:」+ ajaxOptions);
}
});
不能夠解決這個,不知道我做錯了或失去了一些東西 在那裏我有,以便與服務器進行通信,並獲取數據的代碼改變。
您是否在網絡工具中查看了服務器的實際請求/響應,以查看來自服務器的響應實際上有哪些標頭? – jfriend00