简体   繁体   中英

CORS header 'Access-Control-Allow-Origin' missing Cordova

I'm creatring a cordova-appache application where I communicate with a web server (get and post http request to http://192.168.1.1/cgi/json/ ****) in my code javascript I'm using xhr , when I send the first get request, the server respond me with json response and give me a session id and I follow response with wireshark, the fisrt problem http.status return 0 the second problem in the console log i had this message Reason: CORS header 'Access-Control-Allow-Origin' missing.

I added this in config.xml

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

And this to javascript code :

http.open('GET', request_field, true);
        http.setRequestHeader("Access-Control-Allow-Origin", "*");
    http.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    http.setRequestHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS, DELETE, PUT, HEAD");
        http.send();

Like environment i'm using: ubuntu cordova version: 6.1.1 nodejs version :v0.10.25 and Firefox

Your setting in config.xml is effect when you build and run it in mobile. For development you can use my addon: https://addons.mozilla.org/en-US/firefox/addon/cross-domain-cors/?src=ss to enable cross domain and run your app in firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM