ionic XMLHttpRequest cannot load http://localhost:8080/...

来源:互联网 发布:索爱w580c软件 编辑:程序博客网 时间:2024/06/04 17:45

在ionic项目里http请求访问本地API,出现跨域的问题。错误信息:XMLHttpRequest cannot load http://localhost:8080/Moonlighting/area/getAreas Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

解决步骤:

1.在终端项目目录下输入 cordova plugin add cordova-plugin-whitelist

2.在config.xml里添加 :

  <access origin="*"/>


  <allow-intent href="*"/>


  <allow-navigation href="http://*/*" />

3.关闭chrome浏览器,在图标上右键选择属性,快捷方式,在目标栏目的后面添加 --disable-web-security --user-agent="Android" --user-data-dir="C:/temp-chrome-eng,确定

阅读全文
0 0