Cordova: HTTP GET doesn't work in Android -
i'm developing mobile app on cordova. main code communicates local server through http get, example:
$.get( "http://192.168.2.6:8080/getstatus.sha", {}, function(data) { alert ("checkipaddress() success! status: " + data.status); }) .fail(function() { alert ("checkipaddress() failed url \'" + url + "\'."); });
when run code on mozilla firefox, server staus (and more data).
but when run cordova program on android device, "checkipaddress() failed" message.
the local server supports cors. crodova project's config.xml has these settings:
<access origin="*" /> <allow-intent href="http://*/*" />
any suggestions fix error? thanks!
if using cordova 5 , device , server can see each other (on same wifi network) have enable content security policy. see cordova whitelist plugin. want consider adding meta tag
example configuration like:
<meta http-equiv="content-security-policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
depending on else app or doesn't may not need other options in above, although ajax , templating frameworks will. above works cordova 5 app using jquery , handlebars.
Comments
Post a Comment