1

I just updated from Cordova 8 to Cordova 10. Mainly because of Apple deprecating UIWebView. I use cordova-ios@6.1.1. I create a default Cordova project for test purposes. I add no plugins, no other stuff except jQuery version 3.5.1. I add AJAX request to internal application file css/index.css ( this works fine in Cordova 8 ):

function onDeviceReady() {
    // Cordova is now initialized. Have fun!

    console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
    document.getElementById('deviceready').classList.add('ready');

    $.ajax({
        url: "css/index.css",
        success: function (resp) {
            console.log("load OK");
            return false;
        },
        error: function (xhr, status, exc) {
            console.log("load fail");
            return false;
        }
    });
}

When I run the application, the AJAX call fails with status = "error". Please, could anybody advice what was changed and how to make such an AJAX calls working?

user3523426
  • 836
  • 3
  • 11
  • 26
  • 1
    Does this answer your question? [Why is jQuery Ajax not working in Cordova iOS app](https://stackoverflow.com/questions/61567179/why-is-jquery-ajax-not-working-in-cordova-ios-app) – Eric Oct 09 '20 at 15:03
  • Yes, that's it, thanks. Put is as an answer, I'll mark it. – user3523426 Oct 20 '20 at 15:34

1 Answers1

0

You need to move to WKWebView and need to use cordova-plugin-wkwebview-file-xhr or cordova-plugin-ios-xhr since there is file has no origin and will fail with CORS.

Eric
  • 9,870
  • 14
  • 66
  • 102