Software Archive
Read-only legacy content
17060 Discussions

Ajax calls not reporting correct status in Android App Preview

Mark_B_3
Beginner
365 Views

There seems to be a weird bug that only occurs in app preview on Android.

I make an Ajax call to a page that returns a HTTP 403 response, but the status code in the JQuery Ajax callback is 200.

To be clear, this only happens on App Preview for Android.  The same code runs correctly on the Emulator, on App Preview for iOS, and in full builds for both Android and iOS.

Here is some example code:

                $.ajax({
                    type: "GET",
                    url: "http://myserver/mypage", 
                    success: function (result) {
                        // This callback always executes on App Preview for Android regardless of status code
                        
                    },
                    error: function (xhr, status, err) {
                       
                        if (xhr.status == 401 || xhr.status == 403) {
                            // this callback never executes on App Preview for Android
                            app.consoleLog("Access Forbidden");
                        }
                    }
                });

The bizzarre thing is, looking in the console log, the underlying framework knows it is getting a 403 back because it is logging an error, however the Ajax status code is always 200: "Failed to load resource: the server responded with a status of 403 (Forbidden) "

 

 

0 Kudos
5 Replies
Swati_S_Intel1
Employee
365 Views

hmm... This is interesting. So, are you able to get through the request? What is the response text? 

Swati

0 Kudos
Mark_B_3
Beginner
365 Views

Hi Swati,

I checked this out for you. 

The JQuery responseText is "You do not have permission to view this directory or page".  But the JQuery status field is 200, and statusText field is "OK".

And just to reiterate what I said in the first post, the underlying framework knows it is getting a 403 response because it also logs to the console "Failed to load resource: the server responded with a status of 403 (Forbidden)". Something in App Preview that sits between that console log happening and the Ajax callback firing seems to be tampering with the status code I get?

Mark.

0 Kudos
Swati_S_Intel1
Employee
365 Views

Hi Mark,

Thanks for your input. Can you share your working code that accesses the site and gets 403? I would like to debug some more. Also, which android version are you running? And I assume you are using the latest version of App Preview (2.3).

Swati

0 Kudos
Mark_F_
Beginner
365 Views

Any update on this, I'm getting the same issue using Angular JS $http calls

0 Kudos
PaulF_IntelCorp
Employee
365 Views
0 Kudos
Reply