Ajax not working when compiled to APK

I have a relatively simple app which uses the Ajax method to request a text string from an https POST URL. This code works fine as a WebApp deployed to our server, but the same code returns nothing ‘undefined’ when ran as an APK.

I noticed someone else on the forum had this issue and may have resolved it with the contentSecurityPolicy setting but I had no such luck. Any suggestions or somewhere I should look?

One of the first things to check/confirm is that you re calling a url with “https” (not “http”)
On top of that the script on the server side needs to have a CORS header…

Run your app with the Debug window open. You’ll probably see some messages.

Native apps have different security requirements than web apps.

Changing the web server’s literal response to the initial POST request to the following value seemed to work:

Status: 200 OK
Access-Control-Allow-Origin: *
myOutputDataHere

Previously I used the following which worked only on the WebApp:

Status: 200 OK
Content-type: text/plain
myOutputDataHere

Its not a big deal, but it would certainly be worth adding that note to the Ajax sample since that was definitely not obvious or even mentioned.
In otherwords, “When using the Ajax method in compiled APKs you MUST specify CORS in the response header of any POST or GETs.” Feel free to use my examples.