我试图在ripple模拟器上运行我的phonegap应用程序,并在
jquery中使用ajax方法从webservice.asmx调用方法,但是得到了cors错误:
XMLHttpRequest cannot load https:rippleapi.herokuapp.comxhr_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.
>在服务器端(web.config)提供了cors:
< system.webServer>
??????????< defaultDocument>
??????????<文件>
????????????< clear />
????????< add value =“index.aspx”/>
????????< add value =“WebService.asmx”/>
??????< /文件>
????< / defaultDocument>
??????< httpProtocol>
??????????< customHeaders>
??????????????< add name =“Access-Control-Allow-Origin”value =“*”/>
??????????????< add name =“Access-Control-Allow-Headers”value =“Content-Type”/>
??????????< / customHeaders>
??????< / httpProtocol>
??< /system.webServeru0026gt;
??<&的System.Web GT;
????< WEBSERVICES>
??????<协议>
????????< add name =“HttpGet”/>
????????< add name =“HttpPost”/>
??????< /协议>
????< / WEBSERVICES>
????< customErrors mode =“RemoteOnly”defaultRedirect =“mycustompage.htm”/>
??< /system.webu0026gt;
??< system.serviceModel>
>我的AJAX方法:
$就({
????键入: “POST”,
crossDomain:true,
网址:“http://www.my-domain.com/WebService.asmx/selectData”,
data:JSON.stringify(campaignData),
contentType:“application / json; charset = utf-8”,
dataType:“json”,
成功:功能(msg)
{
var response = msg.d;
var resultLoop = $.parseJSON(response);
的console.log(响应)
},
错误:函数(xhr,ajaxOptions,thrownError)
{
$.mobile.loading( ‘隐藏’);
alert(“status:”xhr.status“thrownError:”thrownError“ajaxOption:”ajaxOptions);
}
});
无法解决这个问题,不知道我做错了什么或丢失了什么
我必须在代码中进行更改,以便与服务器通信并获取数据.