0

Using Phonegap, I can't get ajax (or workaround) to work in a release build.

Device being used: Galaxy S4

Situation: with Phonegap App and 'phonegap serve':

  • working: I can POST data to my server using the following method: form with a target of a hidden iframe and an action pointing to my server.
  • not working: traditional ajax calls do not work, either with jquery or straight javascript

With a signed build:

  • neither (form + iframe) or ajax work

===

Things I've already tried:

Set whitelisting via access origin

AndroidManifest.xml has internet permission turned on

Remote server is HTTP, not HTTPS

$.support.cors = true

Downgraded from Cordova 5.0 and Phonegap 5.0 to lower versions

===

Anyone have any suggestions?

user138821
  • 434
  • 8
  • 15

3 Answers3

0

enabling Cors is a complex issue, different clients and different servers have different settings. Mine is client side ajax Cors post call with jason data, Server side is vb.net webservices with access origin set in web.config. If you're using same 'kind' of Server, I can provide you some source codes for reference. I tried testing my client in all known desktop and mobile browsers, as well as Android 4.1.2 thru 4.4.1, and iPhone 4s thru iPhone6+, all work as expected.

Kenneth Li
  • 1,632
  • 1
  • 14
  • 19
0

I ended up using a workaround with the cordova plugin file transfer https://github.com/apache/cordova-plugin-file-transfer

This doesn't exactly solve the underlying problem: if I wasn't trying to upload a file, it still wouldn't work. Luckily I am so this is good enough until it gets fixed.

user138821
  • 434
  • 8
  • 15
0

The whitelist plugin is what finally worked for me.

phonegap plugin add cordova-plugin-whitelist

Then I built my app like normal, and it worked finally!

Hope this helps! L.