AJAX ok in test but not emulate/build

AJAX ok in test but not emulate/build

Hi - hope you'll bear with me as a rank amateur, but I've developed an app in HTML5/Javascript that accesses a mysql database via a php AJAX call. What puzzles me is that it works perfectly in a browser and in XDK emulate mode, but when I run in test mode or build, the php call does not work. An alternative call using plain HTML <form action="http://xxxxx method = "GET">  (ie not AJAX) works perfectly in test and build so the device I'm using (samsung S3 running Android 4.3) would appear not to be the issue. Any pointers much appreciated. Thanks Alan.






23 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Just to say I've seen similar on another forum with solution which is to add script tag <script src="xhr.js"></script> to index.html. It worked!

Yes, that's the solution. It eliminates the CORS issue you're running into.

@Alan B., Where is the script tag linking to --  a cdn, or did you put a copy into in your project? Is it the same xhr.js as this? I'm asking because it's not working for me in tests/builds, only in emulation (as you describe).

There is no xhr.js file in your project, it is "auto-magically" added by the emulator when you run there and by the build system when your app is built. This is also true of the intelxdk.js and cordova.js files. 

Note that you also need to include intelxdk.js in your app, first (before the xhr.js include). The emulator makes the bold assumption that you are going to use the intel.xdk namespace and automatically includes it even if you don't. The real build does not make this assumption.


I put it in the <head> section of index.html, just before the script 'intelxdk.js' which appeared automatically when using the new project wizard. Alan

David - as Paul said, I didn't need to actually have the xhr.js, just put the tag in as above. So I don't know if it was the same version as yours - you don't need to know!

I have the same problem and tried to add the script <script src="xhr.js"> </ script> but I did not solve the problem. Is there any other solution? 
Thank you ...

Hello, same issue working with Cordova 3.5 and App Framework 2.1.
Its run over emulator but doesnt on device. The xhr.js was automatically added into page.

I have a similar problem: the command getRemoteData does not work on tablets, but run OK on smartphone. I made a lot of tests today and I think that the problem is with Cordova 3.5 or 3.5.1.

When I build with these options (3.5 ou 3.5.1), the APP does not work on tablets. 

When I build with version 3.3, the APP runs OK (tablets and smartphones).

I don´t know why these differences (tablets or smartphones). My tests are made on:
Samsung S4 android 4.4.2
Samsung Tab 10.1 I android 4.0.4
Motorola Xoom android 4.1.2

Maybe something about Android version.

What happens when you build using Crosswalk?

I´m not using Crosswalk yet. These situation is on Cordova 3.x Hybrid Android.

I did a lot of tests. If I do not insert XDK Device option, it does not run on any device. If I mark XDK Device, it runs on Samsung S4 (Android 4.4.2) but not on tablets. No error is displayed, just not run. No action ocurrs on server too. 

One more information: if I use Cordova 3.3 to build, the APK works fine on all devices. Using 3.5 or 3.5.1 occurs these problems. The big problem is that Google is advising about Cordova 3.3 and the APK can be removed from Google Play. I need these solution. Thank you.

If you are using App Framework (either directly or because you selected App Framework when you created an App Designer project), there was a bug introduced into version 2.1 of App Framework. This bug was fixed last week. That bug interferes with receiving some Ajax notifications. You can get the most recent versions of the App Framework files from here: https://github.com/01org/appframework/tree/master/build

If you are using App Designer you can safely replace the App Framework files that App Designer inserted into your app with those you download from the repo. App Designer will not write over them, it will respect the updates you make to those files (I recommend you use the same names that App Designer uses for those files).


I changed the appframework.min.js for the new one and the problem is the same. On Samsung S4 runs OK, on Motorola Xoom, no action. No command is sent to server.

I used too then new version of appframework.ui.min.js (v2.1.0 of 2014-11-06) and occurs a new problem: the screen stay black on the left side (almost half). See the image 1. Returning the last one, the screen is OK. See image 2. It occurs on Emulate as on devices.

But it occurs only in large screens device Appel iPad on emulator or Mororola Xoom on device. If I change to a small screen this black part is not present.



Download uiappframe210.jpg35.7 KB
Download uiappframe2.jpg45.04 KB

Use the following URL in your browser to preview a kitchen sink App Framework app:


Once the page is loaded:

  • choose "App Framework UI" from the top menu (second item) or by selecting the AF UI tab at the very bottom
  • find "Side Menu Controls" in the list of Demos
  • push the "Toggle Side Menu" button

Do you see a side menu that works or do you see black?

Sorry, I don't have a version of that app that is put into project format that could be built, but it shouldn't be too hard to do. It is a modification of the App Framework kitchen sink app from the AF github repo. This modification was created by a colleague of mine. He's not in today, so I'm not able to get from him a project that you could put directly into the XDK and build for comparison.

This kitchen sink app should help you see what works and what does not. Note that you need to convert it into a project and perform a build to get a full comparison, because the procedure I outlined above shows the result inside of your device browser, which will be different than the results you get inside of a webview.

Hamilton, I was able to talk to my colleague and he turned that kitchen sink app into a project which you can download and use in the XDK. You'll find the project here: https://github.com/krisrak/html5-kitchensink-cordova-xdk-af 

You can try both, the web version and the webview version to see if you get the problem results you describe. This should help to narrow down the source of the problem.


After your comments I tried to find some menu. I found that:

<div id="menu" class="tabletMenu" style="overflow: hidden;"><div id="menu_scroller" style="-webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);"></div><div class="afScrollbar" style="position: absolute; width: 5px; height: 20px; border-top-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; display: none; background-color: black; top: 0px; -webkit-transition: 0ms; transition: 0ms; background-position: initial initial; background-repeat: initial initial;"></div></div>

I didn´t see it before. There is a new DIV named tabletMenu?

I did not found a command to hide it. Even in the sink demo page this is not presente.

Then, I put in my code:

$('.tabletMenu').css("visibility", "hidden");

I don´t know if it the best solution, but it works.

Now I´m trying to find the problem with the original issue: the getRemoteData do not work in some devices and emulator.

I´m returning to talk about the issue of getRemoteData. I did a lot of tests in my app and the situation is the same: the command getRemoteData works on Samsung Galaxy S4 but does not work on some tablets (Motorola Xoom and Samagung Tab 1).

Then, to isolate the problem and possible programming errors, I did other tests:

- I started a new project using the demo "A sample app showcasing how to use the intel.xdk library (JavaScript bridge library) for hybrid apps."

- I included a new buttom :         <a class="button widget uib_w_7 d-margins" data-uib="app_framework/button" data-ver="0" onclick="funVai()">GetRemoteData</a><span class="uib_shim"></span>

- I created a simple function that is fired onclick (and 2 others functions to be the result of this command):

function funVai() {

- And I builded as Cordova 3.X Android

The issue is the same:

  • it works on emulator (no errors on console)
  • it works on Samsung Galaxy S4 Android 4.4.2
  • it does not work on Samsung Tab 10.1 I Android 4.0.4
  • it does not work on Motorola Xoom Android 4.1.2

Then I build again as Legacy Hybrid. In this compilation, it works OK on all devices.

What is wrong? How can I solve this? Is there another option?

There is a significant difference between the webview in Android 4.4 and <4.4, this is likely the source of the problem. The function was rewritten in order to make it available in a Cordova plugin format, so the code being run in the Cordova build is different than that being run in the legacy build.

I will report a bug, but cannot promise when or if this will be fixed in a reasonable time, since we are trying to encourage use of the public Cordova APIs. As a workaround, I suspect this will work in a Crosswalk build, since that is what the Crosswalk build provides, a well performing webview that is up-to-date. Try this in a Crosswalk build and let me know if it works across all devices.

I build the APP using the legacy option. In this situation, the getRemoteData works well. The problem is that Google Developer Play shows a warning message about the version Cordova (3.3). 

Regarding Cordova 3.3 -- please specify 3.5 in the CLI, this will use Cordova CLI 3.5 to perform the build and will eliminate the warning from Google Play.

Regarding your note about the code below, my suspicion is either your App Framework needs to be updated (find the latest files here: https://github.com/01org/appframework/tree/master/build) or you are encountering a webview issue? The emulator is improperly named, it is not an emulator but a simulator. It only simulates the viewport and user agent of those devices, it does not represent real devices, despite the nice frames around them. When you are running in the emulator you are running in a Chromium browser, you are not running in an emulation of a real device.

Are you trying this using the Debug tab? That will be your best debug environment. When using the Debug tab you will have full access to the Chrome Debug Tools so you can track down what is or is not happening. When using the Debug tab you are running on a real device in the Crosswalk runtime. This is the preferred runtime (rather than the native runtime) for Android devices, because there is such a wide variability in the native webviews found on Android devices. Please test your code using the Debug tab and building with Crosswalk to see if that resolves the issue.

You wrote:

Hamilton Tenóri... 02:49 

I create a simple new APP just for test, using only appframework.

I put these lines (to avoid questions about cross domain restrictions):

$.getJSON("http://time.jsontest.com", function(data){



When I fire this on emulator ou debug (using a tablet Motorola Xoom), everything is OK. The result appers on the window.

But.... if I build (Cordova 3.x Hybrid Android) and try to use on the same tablet or Samsung S4, there is no response.

There is some bug yet with $.ajax, $.post and $.get.

Looking on forum, there are some questions about it. Others have the same problem. Do you know something about it?

Forum Topic: 

AJAX ok in test but not emulate/build







I use XMLHttpRequest, just an alternative and works everywhere, cross-domain or not..

try {
        var method = 'POST'

        var data = decodeURIComponent($.param(dataJson));
        data = data.replace("data:image/jpeg;base64,","");

        var req;

        if(XMLHttpRequest) {
            req = new XMLHttpRequest();

            if('withCredentials' in req) {
                req.open(method, url, true);
                req.timeout = _postTimeout;
                req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                req.onerror = makeAjaxPostError;
                req.onreadystatechange = function() {
                    if (req.readyState === 4) {
                        if (req.status >= 200 && req.status < 400) {
        } else if(XDomainRequest) {
            req = new XDomainRequest();
            req.timeout = _postTimeout;
            req.open(method, url);
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            req.onerror = makeAjaxPostError;
            req.onload = function() {

        } else {

    }catch(e) {


Leave a Comment

Please sign in to add a comment. Not a member? Join today