Javascript 无法加载XMLHttpRequesthttp://localhost:8088/web/webclient/version_info ionic登录到odoo服务器时出错
当我尝试使用ionic应用程序登录到odoo服务器时。我得到下面引用的错误。如果是因为CORS,我如何在本地odoo服务器中配置而不使用nginxJavascript 无法加载XMLHttpRequesthttp://localhost:8088/web/webclient/version_info ionic登录到odoo服务器时出错,javascript,android,angularjs,ionic-framework,openerp,Javascript,Android,Angularjs,Ionic Framework,Openerp,当我尝试使用ionic应用程序登录到odoo服务器时。我得到下面引用的错误。如果是因为CORS,我如何在本地odoo服务器中配置而不使用nginx XMLHttpRequest cannot load http://localhost:8088/web/webclient/version_info. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in t
XMLHttpRequest cannot load http://localhost:8088/web/webclient/version_info. 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.
使用您的IP地址,而不是
localhost
。例如:
http://192._._._:8088/web/webclient/version_info
默认情况下,出于安全原因,浏览器会阻止跨域请求,但我们可以通过以下方式实现跨源请求 打开Chrome并安装这个插件,然后尝试发送请求,它会工作,但这不是一个好主意 第二个想法 最好的方法是转到您的中间件,并将标题添加为 “访问控制允许源:*” 它将允许来自不同域的所有请求。对于节点Js
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
添加cordova白名单插件
cordova plugin add cordova-plugin-whitelist
准备
cordova prepare
在config.xml中添加以下行
<access origin="*"/>
<allow-intent href="*"/>
<allow-navigation href="http://*/*" />
对于MacOSX
open -a Google\ Chrome --args --disable-web-security --user-data-dir="/Users/thantshweaung/Documents/Project/ionic/chrome_cache"
解决了 实际上我用的是IP地址。谢谢。我已经安装了插件,还按照你的建议配置了标题。但仍然存在错误。一旦chrome上的“安装检查CORS”按钮显示为绿色,则只有该按钮才能工作。请尝试重新启动该按钮。如果是nodejs,则可以使用哪种语言编写服务器端代码。setHeader('Access-Control-Allow-Origin','*');//请求您希望允许的方法res.setHeader('Access-Control-allow-methods','GET,POST,OPTIONS,PUT,PATCH,DELETE');//请求头您希望允许res.setHeader('Access-Control-allow-headers','X-Requested-With,content-type');//如果您需要网站在发送给API的请求中包含cookie(例如,如果您使用会话)res.setHeader('Access-Control-Allow-Credentials',true),则设置为true;奥多兄弟。那个ERP系统使用python语言。感谢您使用名为
open -a Google\ Chrome --args --disable-web-security --user-data-dir="/Users/thantshweaung/Documents/Project/ionic/chrome_cache"