5 Replies Latest reply on Apr 7, 2016 1:34 PM by wtaveras

    Ajax call problem from mobile

    wtaveras

      Hi,

       

      I'm having a problem with ajax calls using Cordova 6.1.1 and I can't make it work. Here is what I did already:

       

      1. Add the following lines in my config.xml

       

      <allow-navigation href="*" />
      <access origin="*" />

       

      2. Add header('Access-Control-Allow-Origin: *') in PHP page.

      3. Make requests using jsonp, get, post, ajax

      4. Adding both, mobile and computer to same network

      5. Using an public/external accessible website in order to test post

      6. Checked that internet is allowed in the AdroidManifest.xml file


      Everything works fine if I open my index.html file from the web browser, getting the expected result. I'm also able to call my php page (hosted in my local computer for development) from the mobile's web browser and it works fine.


      I need help, I'm loosing a lot of time trying to make this work, considering using another framework to develop, so I can finish with this project.

      PLEASE HELP!!

        • 1. Re: Ajax call problem from mobile
          wtaveras Level 1

          Update:


          I created the .apk file and I'm able to make ajax requests, so the problem is when using simulator.

          Repeat: Works on computer browser, works using Rippled on Chrome and now works installing the app in the phone.


          Help!

          • 2. Re: Ajax call problem from mobile
            kerrishotts Adobe Community Professional

            What emulators are you testing on?

            • 3. Re: Ajax call problem from mobile
              wtaveras Level 1

              I'm using EvothingsWorkbrench and now a plugin for Chrome (Rippled). Any suggestion? An emulator you recommend?

               

              I need help, so I can test in an emulator, not building the app and installing on the phone.

              • 4. Re: Ajax call problem from mobile
                kerrishotts Adobe Community Professional

                Neither of those things are emulators AFAIK. They can be useful for testing, but they can also introduce additional complexity when they don't act exactly as you might expect. Since I use neither, it's difficult for me to be of any assistance in that regard.

                 

                You can use the emulator shipped with the Android SDK or something like GenyMotion. These emulators use an Android image to provide, essentially, Android on your desktop. They aren't exactly the same as running the app on your device (typically slower, and lacking in sensors, or provide mock sensor data), but the environment is far closer to the real thing than what you're currently using (AFAIK).

                 

                Depending on which emulator you use, you'll use different Cordova commands:

                 

                • cordova emulate android --> launches the Android SDK emulator (you have to configure at least one emulator in advance)
                • Configure and launch a GenyMotion Android emulator --> cordova run android --> app runs on the emulator

                 

                Hope that helps.

                • 5. Re: Ajax call problem from mobile
                  wtaveras Level 1

                  Thank you for the answer. I'll try with that and let you know the results.

                   

                  I added the parameter "timeout: 5000" to my Ajax Request and I get the error "Timeout". Any idea what happen? I get that error only when executing from the "emulator".

                  Something with the Content-Security-Policy rules? Can I know what should I put there (In the Content-Security-Policy)?

                   

                  Thanks in advance!!