Why can't I connect my Android device to localhost using the Intel XDK app? -
i'm novice in app development. i'm using intel xdk make android app.
the app works connecting database in backend done symfony, , behaving fine in emulator. want test real device, using pc localhost, through wifi. read have retrieve localhost ip address ipconfig, , use ip connection. however, when test app doesn't connect. strange thing if use mobile browser same url, connection works: can see xml files use fetch database information.
the code connection in app:
xmlhttp=new xmlhttprequest(); xmlhttp.onerror=transferfailed; xmlhttp.open("get","http://192.xxx.x.x/symfony/web/app_dev.php/api/v1/reportes/reportes.xml",false);
the onerror function:
function transferfailed(e) { alert("error al conectar:"+e.target.status); }
as said, connection doesn't work , alert message: "error al conectar: 0"
if put address http://192.xxx.x.x/symfony/web/app_dev.php/api/v1/reportes/reportes.xml
in mobile browser correct xml file.
edit: seems problem sycnhronus request. later had parse response xml. dont' know why in emulator , in app made in phonegap time ago worked without parse. code:
function mapini() { xmlhttp=new xmlhttprequest(); xmlhttp.onerror=transferfailed; xmlhttp.open("get","http://localhost/symfony/web//app_dev.php/api/v1/reportes/reporte.xml",true); xmlhttp.onload= function (event) { alert("onload:"+xmlhttp.response); }; xmlhttp.onreadystatechange = function() { if(xmlhttp.readystate == 4 && xmlhttp.status == 200) { xmldoc=xmlhttp.responsexml; xmldoc=xmlhttp.responsexml; xmldoc = new domparser().parsefromstring(xmlhttp.responsetext,'text/xml'); x=xmldoc.getelementsbytagname("entry"); alert("x[0]:"+x[0].getelementsbytagname("tipo")[0].childnodes[0].nodevalue); } } xmlhttp.send(); }
it may failing because of cross-origin request, add script tag: <script src="xhr.js></script>"
, try on device. don't need actual xhr.js
file, add script tag in index.html
, intel xdk build include workaround cross-origin policy.
Comments
Post a Comment