0

I've been stuck here for quite some time now. I am developing a mobile application with phonegap. I have tested the app with android 4.0.4 and it is working perfectly fine. However, when I tested on 2.2.3, the AJAX ended with and error state of:

ready state = 0

HTTP Status = 0

I have tried to increase the timeout to be really long but it still ends with that result. I am not sure what is the problem but I have developed another app using the same ajax call and it is working fine on android 2.2.3 but what makes this time different is that it calls to a SAML URL (Identity Provider).

the codes is like bellow:

$.ajax({
                url: "...."+Math.random(),
                type: "POST",
                data: {
                    j_username: uname,
                    j_password: pword
                },
                cache: false,
                timeout: (100*1000),
                success: function(data, textStatus, jqXHR){
                    var contentType = jqXHR.getResponseHeader('Content-Type');
                    if (contentType == 'application/atomsvc+xml'){
                    }else{
                        alert(".....");
                        // clearTimeout(timer);
                        $.mobile.hidePageLoadingMsg();
                        enableAllButtons();
                    }
                },
                error: function(jqXHR, textStatus, errorThrown){
                    // clearTimeout(timer);
                    alert("Error Thrown : " + errorThrown);
                    alert("status : " + jqXHR.status + " " + jqXHR.statusText);
                    alert("ready state : " + jqXHR.readyState);
                    alert(".......");
                    $.mobile.hidePageLoadingMsg();
                    enableAllButtons();
                }
            });  

Really hope someone can help me with this.

Thank you very much for your input in advance.

Regards,

Amanda

Amanda
  • 21
  • 4

1 Answers1

0

The code seems to be fine except one thing

You are using Math.random() in the URL.. You also use cache:false Try to remove the Math.random() from URL while jQuery Cache uses the same thing.

Also, while you get readyState = 0 then it will be a CrossDomain issue. Use JSONP for that (dateType:'JSONP') in AJAX options

Alaa Badran
  • 1,848
  • 15
  • 19
  • Hi Alla, I tried to run on the eclipse emulator for android 2.2.3 and it worked perfectly fine. I think its the crossDomain issue but actually I have already connected to my VPN via anyconnect. Do you have any advice as to how I might be able to resolve this cross domain issue. Particularly for Android 2.2.3 because on the ohter version is working fine. – Amanda Mar 28 '13 at 09:53
  • if you are suing jQuery, then you have to read about this: http://stackoverflow.com/questions/11736431/make-cross-domain-ajax-jsonp-request-with-jquery – Alaa Badran Mar 28 '13 at 12:04