2016-04-04 6 views
1

Ich erstelle eine cordova-appache-Anwendung, wo ich mit einem Webserver kommunizieren (http und HTTP-Anfrage zu http://192.168.1.1/cgi/json/ ****) in meinem Code Javascript Ich benutze xhr, wenn ich die erste Anfrage senden, antworte der Server mir mit JSON Antwort und gebe mir eine Session ID und ich folge Antwort mit wireshark, das erste Problem http.status zurück 0 das zweite Problem in der Konsole log i diese Nachricht hatte Reason: CORS header 'Access-Control-Allow-Origin' missing.CORS-Header 'Access-Control-Allow-Origin' fehlt Cordova

ich dies in config.xml hinzugefügt

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

Und dies 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(); 

wie Umwelt ich verwende: ubuntu cordova Version: 6.1.1 NodeJS Version: v0.10.25 und Firefox

+0

'' in 'config.xml' – Rayon

+0

getan, aber funktioniert nicht !!! – mntsr

+0

Senden Sie Header von Ihrem 'Webservice'? – Rayon

Antwort

0

in Config Ihre Einstellung. XML ist ein Effekt, wenn Sie es in Mobile erstellen und ausführen. Für die Entwicklung können Sie mein Addon verwenden: https://addons.mozilla.org/en-US/firefox/addon/cross-domain-cors/?src=ss, um Cross-Domain zu aktivieren und Ihre App in Firefox zu starten.

+0

Hallo Tan Mai Van, ich habe das gleiche Problem, CORS-Header 'Access-Control-Allow-Origin' fehlt – mntsr

+0

Ich habe die gleiche Nachricht : Cross-Origin-Anforderung blockiert: Die Richtlinie "Gleiche Herkunft" lässt das Lesen der Remote-Ressource unter http://192.168.1.1/cgi/**** nicht zu. (Grund: CORS-Header 'Access-Control-Allow-Origin' fehlt). – mntsr

+0

Welche Version von Firefox benutzt du? –