- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is the code: function apiCall(action, params) { var callURL = siteURL + apiURL + "action=" + action + "&" + params, xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", callURL, false); xmlHttp.send(); return xmlHttp.responseText; }
This is the error:
Uncaught NetworkError: A network error occurred. /C:/Users/MYUSERNAME/AppData/Local/Intel/XDK/xdk/components/client/emulator/ripple.js:60282 (anonymous function) /C:/Users/MYUSERNAME/AppData/Local/Intel/XDK/xdk/components/client/emulator/ripple.js:60282 apiCall gingerlib.js:17 doLogin gingerlib.js:26 onclick index.html:79
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
bump
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, but not much to go on with the info you've provided. Does this work in a standard browser? Did you try it using an Android 4.x device attached with USB and using the Debug tab? Nothing about your code is XDK-specific. Was your network connection working when you performed the test?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When run on the device, using debug it does nto work causing a Network Error.
Network connections was up
It just seems like the XMLHttpRequest does not work with Intel XDK at all :(. This is the app header:
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <script src="intelxdk.js"></script> <script src="xhr.js"></script> <meta http-equiv="Pragma" content="no-cache"> <script type="text/javascript" charset="utf-8" src="intelxdk.js"></script> <script type="text/javascript" src="js/gingerlib.js"></script> <script type="text/javascript" language="javascript"> // This event handler is fired once the intel libraries are ready function onDeviceReady() { //hide splash screen now that our app is ready to run intel.xdk.device.hideSplashScreen(); setTimeout(function () { $.ui.launch(); }, 50); } //initial event handler to detect when intel is ready to roll document.addEventListener("intel.xdk.device.ready", onDeviceReady, false); </script> <script type="text/javascript" style=""> </script> <script src="js/appframework.ui.min.js"></script> <script> $.ui.autoLaunch = false; $.ui.useOSThemes = true; //Change this to false to force a device theme $.ui.blockPageScroll(); $(document).ready(function () { //if ($.ui.useOSThemes && !$.os.ios && $("#afui").get(0).className !== "ios") // $("#afui").removeClass("ios"); }); </script> <link href="css/icons.css" rel="stylesheet" type="text/css"> <link href="css/af.ui.css" rel="stylesheet" type="text/css">
That function was in gingerlib.js
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Put your code inside the onDeviceReady() function, otherwise it will run before the underlying XDK subsystem is ready.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is only intitiated on a user clicking a button, so it can't be before onDeviceReady().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your inclusion of gingerlib.js must contain code that is getting executed and causing the error before the underlying device and xdk JS files are ready. Turn your gingerlib.js file into definition code, only and put the init code inside of it into onDeviceReady().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've changed some stuff around:
This is my header:
<head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta http-equiv="Pragma" content="no-cache"> <script> window['_native_XMLHttpRequest'] = window.XMLHttpRequest; // xhr.js store it too, but for good measure we do it on our own </script> <script type="text/javascript" charset="utf-8" src="intelxdk.js"></script> <script src="xhr.js"></script> <script type="text/javascript" language="javascript"> var isIntel=window.intel&&window.intel.xdk // This event handler is fired once the intel libraries are ready function onDeviceReady() { //hide splash screen now that our app is ready to run intel.xdk.device.hideSplashScreen(); setTimeout(function () { $.ui.launch(); }, 50); } //initial event handler to detect when intel is ready to roll document.addEventListener("intel.xdk.device.ready", onDeviceReady, false); </script> <script src="js/appframework.ui.min.js"></script> <script> if(isIntel) $.ui.autoLaunch = false; $.ui.useOSThemes = true; //Change this to false to force a device theme $.ui.blockPageScroll(); $(document).ready(function () { if ($.ui.useOSThemes && (!$.os.ios||$.os.ios7)) $("#afui").removeClass("ios"); }); </script> <link href="css/icons.css" rel="stylesheet" type="text/css"> <link href="css/af.ui.css" rel="stylesheet" type="text/css"> <script src="js/myScript.js" type="text/javascript"></script> </head>
Then, this is a fucntion in my Javascript file myScript
function apiCall(action, params) { var callURL = siteURL + apiURL + "action=" + action + "&" + params; xmlHttp = null; xmlHttp = new window['_native_XMLHttpRequest']; xmlHttp.open("GET", callURL, false); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { //Request is complete if(xmlHttp.status == 200) { //Response is ready alert("Request succeeded. Data: "+xhr.responseText); } else { alert("NetError:"+xmlHttp.readyState+" "+xmlHttp.status); return null; } } } xmlHttp.send(null); return xmlHttp.responseText; }
I always get "NetError: 4 0"
The only thing in the init of the Javascript file is declaring two variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you able to build a test version that removes the suspect libraries and then add them back, one by one (or remove, one by one) to determine which might be causing the problem? The trouble is there are many unknowns in your code, so it needs to be isolated before we can really start to provide a fix.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page