Ajax sample project not work

I just upgraded the software from version 9.0.4.3 to 9.1.5.1 and found my old Basic DB project build with error in Voltbuilder. After change the and add in config.xml. It can build the Android Native apk, but it have errors when opening the DB and Ajax call.

I try to test the Ajax call with the sample project - Ajax, it work fine in Web app, but after building the android native apk and installed in the mobile phone, it return req.status = 0 when I click the button.

If I need to build the native apk with DB function, should I use SQLite (WASM) or cordova? If use cordova plugin, should I use <plugin name = "cordova-sqlite-storage" spec = "5.0.0" />
or <plugin name="cordova-plugin-androidx-adapter" />?

You’re hitting cross origin permissions as you’re not running the app from the same place as your database.

The suggestion by @lotsofcows is a good one.

What errors are you seeing?

To use SQLite on native apps, I’ve used this one:

<plugin name="cordova-sqlite-evcore-extbuild-free" source="npm" />

See cordova-sqlite-storage - npm

I still fail in the Ajax sample project on native apk. I uploaded the ajax.php to my server location “https://XXXX.com/” and only change the req=Ajax(“ajax.php/?myText=” + txtSend.value, done) to req=Ajax(“https://XXXX.com/ajax.php/?myText=” + txtSend.value, done). Using the 9.1.5.1 to build the web app, it work fine, but when I build the native apk, it return “Error: Status = 0”.

In my old project build the native apk with 9.0.4.3 on last year September is working fine in the very beginning, but it have a funny behaviour now. When reinstall the apk on the phone, the Ajax call is working fine. After exit the app and reopen again, it cannot access the Ajax call any more. The only way to make it work again is reinstall the apk or clear data in the Settings - App.

I try to build my old project with latest 9.1.5.1, it even won’t work after first install. Please help.

I try to build the apk for the Ajax sample project and install on Android 7 mobile, it work fine, but not in Android 12 & 15 mobile. Is it the Content Security Policy? How to define the CSP?

First step is to see what messages you are getting on the remote Chrome Console.

Problem solved by adding the following line in the PHP code.

header('Access-Control-Allow-Origin: *');