JavaScript XMLHttpRequest or AJAX Calls in native mobile Application

Hello everyone,

I am an Outsystems developer, and in my free time i keep up with the last Outsystems trends practicing in home projects.

I am making a native application to support house IOT (Internet of things), so it can display sensors information, gate status, etc. All that sensor information is provided by a rest API deployed on Apache Web Service (in local network).
Those REST API's are accessible from outside the local network by port forwarding.

Everything works great, and my application consumes those rest services, displaying the correct data.

Now, i have a problem, my internet connection often crashes (3G in remote area), and i am not able to use this application, since it relies on internet to get information from the rest services.

I had the idea, that i could make the rest calls directly from javascript, thus, connecting directly to my localhost server (on local network), even when the connection to Internet is down. This would also improve the the application speed since i am taking photos from a web cam, and it takes a while when internet speed is slow.

When i am outside my network i would call the public URL.

I made the javascript code in the attachment.

The problem: This code works fine, when i run the application on the browser (computer or mobile phone). However, when i run the native application, it does not work.

Is there a problem using XMLHttpRequest in native apps? I also tried with $ajax call and the behaviour is the same.

I posted several "alert's" on the code, and the only alert that is issued is this one:
alert("After SEND ALERT") 

It seems that he does not get any answer (nor error, success, timeout, etc)

Can someone help?

Thank you,

Vasco Mendes

Hello Vasco.

I didn't understand the reason why you couldn't use the REST API consume feature of the platform. You should be able to use it.

Anyway, are you testing the app in the foreground or background? When the app goes to background, javascript might stop executing.