AJAX locked when using cdvfile - Phonegap

Running AJAX from packed files (for example, the location " file : ///android_asset/www/index.html") works well, but does it from local files (for example, " cdvfile : //localhost/persistent/TEST/index.html ") does not.

I suppose this is due to policies of the same origin . Is there anything that can be done to make it work?

If I were reading files from the Internet, I would set up a web server to add the headers "Access-Control-Allow-Origin", but there is no web server. Using jsonp will work, but it will mean changing the code on the server and in the application.

This is testing on Android 4.1.2 and 4.4.2 using Phonegap 3.4.

+1
source share
1 answer

In fact, using toNativeURL instead of toURL fixes the problem, since toNativeURL uses the file protocol instead of the cdvfile protocol.

It also does the job window.location = pathToLocal; work in Phonegap 3.5 (cf my other question It is impossible to change the location to a local file, for example cdvfile: //path/index.html in Phonegap 3.5 ).

+2
source

Source: https://habr.com/ru/post/1201528/


All Articles