title: Why is jQuery Ajax not working in Cordova iOS app
body: <p>I am building a Cordova app that uses jQuery Ajax to upload images to our server. The uploads were working for a while on both Android and iOS, then after a while they suddenly stopped working on iOS. Now, after a few seconds of trying to access a website, the request fails and I get an error message, which isn't much help. The error is like the following:</p>
  
  <pre><code>readyState: 0
  status: 0
  statusText: "error"
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>    $.ajax("http://testapi.com/api", {
          data: submission,
          processData: false,
          contentType: false,
          method: "POST",
          // submission was successful
          success(data) {
            if (JSON.parse(data).success) {
              // backend validated and accepted submission
            } else {
              // backend rejected submission due to validation errors
            }
          },
          // submission failed
          // eslint-disable-next-line no-unused-vars
          error(xhr, text, error) {
            alert(
              JSON.stringify(xhr) + "  " + text + " " + JSON.stringify(error)
            );
          }
        });
  </code></pre>
  
  <p>My Content Security Policy, in index.html is:</p>
  
  <pre><code>&lt;meta http-equiv="Content-Security-Policy" content="default-src * blob: gap://* file: http: https: ; style-src 'self' 'unsafe-inline'; script-src * blob: file: 'unsafe-inline' 'unsafe-eval' http: https: ; img-src 'self' data: blob: file: ; media-src * blob: file:  http: https: ;"
  </code></pre>
  
  <p>And config.xml is:
      `
          
          
          
          </p>
  
  <pre><code>    &lt;config-file parent="NSCameraUsageDescription" target="*-Info.plist"&gt;
          &lt;string&gt;World Bee Count needs access to your camera and photo library&lt;/string&gt;
      &lt;/config-file&gt;
      &lt;edit-config file="*-Info.plist" overwrite="true" target="NSLocationWhenInUseUsageDescription"&gt;
          &lt;string&gt;need location access to find things nearby&lt;/string&gt;
      &lt;/edit-config&gt;
      &lt;edit-config file="*-Info.plist" overwrite="true" target="NSLocationAlwaysAndWhenInUseUsageDescription"&gt;
          &lt;string&gt;need location access to find things nearby&lt;/string&gt;
      &lt;/edit-config&gt;
      &lt;string file="*-Info.plist" overwrite="true" target="NSLocationAlwaysUsageDescription"&gt;
          &lt;string&gt;need location access to find things nearby&lt;/string&gt;
      &lt;/string&gt;
      &lt;config-file parent="NSPhotoLibraryUsageDescription" target="*-Info.plist"&gt;
          &lt;string&gt;World Bee Count needs access to your camera and photo library&lt;/string&gt;
      &lt;/config-file&gt;
      &lt;preference name="StatusBarOverlaysWebView" value="false" /&gt;
      &lt;preference name="StatusBarBackgroundColor" value="#2D81C1" /&gt;
      &lt;preference name="Fullscreen" value="true" /&gt;
      &lt;feature name="CDVWKWebViewEngine"&gt;
          &lt;param name="ios-package" value="CDVWKWebViewEngine" /&gt;
      &lt;/feature&gt;
      &lt;preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" /&gt;
      &lt;preference name="WKWebViewOnly" value="true" /&gt;
  &lt;/platform&gt;
  &lt;engine name="ios" spec="5.1.0" /&gt;
  &lt;plugin name="cordova-plugin-geolocation" /&gt;
  &lt;plugin name="cordova-plugin-device" /&gt;
  &lt;plugin name="cordova-plugin-file" /&gt;
  &lt;plugin name="cordova-plugin-filepath" /&gt;
  &lt;plugin name="cordova-plugin-whitelist" /&gt;
  &lt;plugin name="cordova-plugin-add-swift-support" /&gt;
  &lt;plugin name="com.subitolabs.android.cordova.galleryapi" spec="https://github.com/Collaborne/cordova-gallery-api.git"&gt;&lt;/plugin&gt;
  &lt;plugin name="cordova.plugins.diagnostic" /&gt;
  &lt;plugin name="cordova-plugin-android-permissions" /&gt;
  &lt;plugin name="cordova-plugin-splashscreen" source="npm" /&gt;
  &lt;plugin name="cordova-plugin-camera-preview"&gt;&lt;/plugin&gt;
  &lt;plugin name="cordova-plugin-wkwebview-engine" spec="~1.2.1" /&gt;
  &lt;plugin name="cordova-plugin-screen-orientation" spec="~3.0.2" /&gt;`
  
  &lt;access origin="*" /&gt;
  &lt;allow-intent href="*" /&gt;
  &lt;allow-navigation href="*" /&gt;
  </code></pre>
  
  <p>I am running this on iOS 13 and using PhoneGap build</p>
  
  <p>My problem is most similar to this
  <a href="https://stackoverflow.com/questions/32706656/ajax-not-working-in-ios-9-0-cordova">Ajax Not working in IOS 9.0 Cordova</a></p>
  
  <p>I tried updating my config.xml according to this <a href="https://stackoverflow.com/questions/33676673/how-to-add-nsapptransportsecurity-to-cordova-project">question</a>
  But it doesn't seem to be working</p>
  
  <p>Any help is would be very much appreciated, I've been working on this for hours and can't seem to get anywhere</p>