加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

请求的资源ajax jquery phonegap上没有“Access-Control-Allow-O

发布时间:2020-12-16 02:46:49 所属栏目:百科 来源:网络整理
导读:我试图在ripple模拟器上运行我的phonegap应用程序,并在 jquery中使用ajax方法从webservice.asmx调用方法,但是得到了cors错误: XMLHttpRequest cannot load https:rippleapi.herokuapp.comxhr_proxy?tinyhippos_apikey=ABCtinyhippos_rurl=http%3A//www.my
我试图在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);
}
});

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

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读