Software Archive
Read-only legacy content
17061 Discussions

$.ajax call always results in call to "error" function in android app. Works fine in App preview

Niharika_K_
Beginner
538 Views

For my Cordova based application, I have generated the android apk for the first time.

I make an ajax post as shown below.  But everytime I do this, the error function is getting called. I never see the success function being called. Inside the error function I notice that the parameter "textStatus" shows "Error". But the parameter "errorThrown" is just blank.

Please note that if I app using the "test" tab on Intel XDK on my Laptop and then open the app via "App preview" on my phone everything works fine. I am not able to find out the reason why it works file in APP preview but fails when I create an android APK. I have enabled all Cordova plugins just to avoid any plugin related issues. From the code when I check the connection type, it correctly shows the connection as "WiFi" so it does not seem to be a data connection issue. Would you guys know the reason for the failure. The ajax post code is given below. I have generalized the call by removing the actual data and retained only the syntax I am using.

=====================================================

$.ajax({
        url: '<my_URL>',
        type: 'POST',
        data: {json: <jason data>, cmd:<some command>},
        async: false,
        success: function(msg) {
                     //Success Code here
        }
        error: function (jqXHR, textStatus, errorThrown) {
                        //Control Always reaches here.
                         textStatus: Error
                         errorThrown:
         }

=====================================================

Regards,

Niharika

 

 

0 Kudos
2 Replies
Dale_S_Intel
Employee
538 Views

I'm not sure what the problem is, but I can make a few suggestions.  First I would try it in the Debug tab.  This will likely work the same as in AppPreview, but you may be able to snoop around the debugger and check some things.

The other thing I would do is try building your app as a Crosswalk app, which again is more similar to the way it is run in App Preview.

0 Kudos
Niharika_K_
Beginner
538 Views

Hi Dale,

I tried the second option of trying to build the Crosswalk app. Now when the ajax code runs I get the error "Error : Not Found"

Is the Ajax part of the code missing something ?

Regards,

Amit

0 Kudos
Reply