Software Archive
Read-only legacy content
17060 Discussions

AJAX ok in test but not emulate/build

Alan_B_
Beginner
1,553 Views

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.

 

 

 

 

 

0 Kudos
23 Replies
PaulF_IntelCorp
Employee
217 Views

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:

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

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

1 $.getJSON("http://time.jsontest.com"function(data){
2     alert(JSON.stringify(data));
3 });

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: 

 

 

 

 

0 Kudos
Ömer_G_
Beginner
217 Views

Hi,

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) {
                            
                            
                        } 
                    }
                };
                req.send(data);
            }
        } 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() {

            };
            req.send(data);
        } else {

        }
    }catch(e) {

    }

0 Kudos
Bartolomeu_Uicaa_D_
217 Views

Boa noite, o meu está acontecendo o contrario, só consigo compilar para Tablet, vcs sabem onde está meu erro?

 

Good night, mine is happening the other way around, I can only compile for Tablet, you know where my error is?
0 Kudos
Reply