微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

请求的资源ajax jquery phonegap上没有“Access-Control-Allow-Origin”标头

我试图在ripple模拟器上运行我的phonegap应用程序,并在 jquery中使用ajax方法从webservice.asmx调用方法,但是得到了cors错误

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.

>在服务器端(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.webServer\u0026gt;
  <&的System.Web GT;
    < WEBSERVICES>
      <协议>
        < add name =“HttpGet”/>
        < add name =“HttpPost”/>
      < /协议>
    < / WEBSERVICES>
    < customErrors mode =“RemoteOnly”defaultRedirect =“mycustompage.htm”/>
  < /system.web\u0026gt;
  < 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);
}
});

无法解决这个问题,不知道我做错了什么或丢失了什么
我必须在代码中进行更改,以便与服务器通信并获取数据.

解决方法

在ripple模拟器上运行phonegap应用程序,将跨域代理设置更改为禁用并且它工作正常.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐