AJAX calls to REST services are not working

  • 1
  • Question
  • Updated 4 years ago
Calling ajax service are not initiating and the website act as static page. Please provide support for any configuration for running the ajax calls. Normal web application is working fine. I am using latest phonegap 0.2.3 no CLI simply creating my application with HTML5 CSS and Jquery with AJAX. Only issue im facing is no rest service calls through AJAX is initiating.
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I am using latest phonegap 0.2.3
There is no such Phonegap Build version
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
okk Petra I have simple responsive web page and script i wish to generate hybrid IOS and andoird app with phonegap what I can do any help from ur side.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Has your web page been constructed with client side techniques, only? No server side techniques, like php, database interface calls, etc?

Do you have icons and splashes for iOS and Android prepared?

Do you require any device functionality like sensors, camera, gps or network/device information? If so, did you find and implement plugin logic in your code?

Did you prepare a config.xml, including whitelisting for your web services?

====
If you have all this, and created a zip file for PGB, please make your zip file available online somewhere, and post its url here. I'll be happy to have a look and provide feedback.
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
Hi Petra I am sharing my code please go through as all pages are HTML5 ,CSS and JQuery built code. and web services are being called using ajax in javascript. If u can verify why sjax calls are not being initiated and whitelisting is not proper please tell me. I used default project structure created by PGDesktop app and added my HTML code files.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Well, it's quite obvious:

1. You are uploading a full Cordova project, including hooks, platforms, plugins, etc. You can't do that. PGB only requires your assets and a config.

2. You don't have both config.xml and index.html in the root of your zip file. You should, however.
Best way to do that:
a. Move config.xml into /www
b. adjust paths to your icons/splashes
c. zip up only the CONTENTS of /www (not the directory itself)

3. You are using the old, deprecated plugins from the pgb repo. Don't do that.
Instead, use the latest versions of the plugins from npm. Be aware that they are named differently!
See the Plugins section of the PGB Docs and the Blog from September 04, 2015

4. (not related) Remove everything related to Blackberry, since this OS isn't built by PGB, anyway.
Also remove everything related to Winphone, since you are not building for that OS.

5. You have <plugin version="1" name="cordova-plugin-whitelist"/>
Remove the version attribute, since version-1 does not exist.
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
Hi Petra thanks for your answers but the major problem I am facing right now is the ajax url access as I am getting forbidden error on ajax calls which is a result of whitelisting I guess not sure about that. I tried writing meta tag for CSP but it generated a lot of issues like CSS and Jquery not loaded. And I was testing on phonegap developer app with desktop and till now no success with ajax calls.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Did you change/correct everything as suggested? If so, please post your new zip file. Also, you should not test with the PG Dev App, as it is not compatible with PGB. Use real devices to install and test.
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
Yes Petra Check out this build I created and tell wat else I need to update : https://www.dropbox.com/s/dnto1wkm48d...
Photo of Chris Griffith

Chris Griffith, Champion

  • 347 Posts
  • 92 Reply Likes
PhoneGap 0.2.3 refers to the PhoneGap Desktop App's version code.

Project generated with that tool are not easily made compatible with PhoneGap Build. You will need to pick a solution (PhoneGap Build or the CLI/Desktop) for you development process.

As to your issue, it probably lies in the not enabling whitelisting and access to external resources. Search this forum on those topics for solutions.
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
can u help me out in whitelisting the ajax url as my application is running on both ios and android device and access origin is set to (*) in config.xml by default. Currently my application behaves as static app. As I am a newbie to phonegap and looking for the easy process of creating app so I choosen desktop version of phonegap I will be very thankful for your help.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sarvan,
it appears you are using PhoneGap Desktop App. As Chris stated, you should choose between CLI/Desktop or Phonegap Build

You should also know, phonegap is not a webserver or a webbrowser.

Also, are you aware that both Google and Apple frown on apps that are website wrappers?

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Isn't this topic about using REST interfaces? Nowhere - as far as I can see - is OP intending to display a website in the app.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
and the website act as static page.

The OP is using the website page as an asset. Did the OP really mean this? I don't know.

Only issue im facing is no rest service calls through AJAX is initiating.

What is happening with the REST service call is not clear, except it does not work.

Your guess is as good as mine as to the architecture.

Jesse
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
Hey Jesse do you have any idea what I can do in PhoneGap desktop application to make my ajax calls work. Please support..
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sarvan,
To be clear, my system is Linux. I do not own Windows or Mac. I cannot tell you how to fix Desktop App. I can tell you this:

Canned Message
I need to blog this, so i don't have to repeat this answer again and again.

You cannot use Phonegap Desktop App with Phonegap Build.

Phonegap Desktop App uses Phonegap CLI, so if you want to use Phonegap Desktop App you need to stay with Phonegap CLI.

If you want to use Phonegap Build, then forget what you have done and start over _OR_ make Minor modifications to move Phonegap Desktop App to Phonegap Build. To be clear, the difference is minor, but enough to keep tripping you.

Also, you will not be able to use Phonegap Developer App as that is meant to work with Phonegap Desktop App. You cannot use either CLI or Build with Developer App.

FWIW: I've been trying to get Phonegap to fix this. Here is the report on the issue.

Let me know what you want to do.
Jesse
Photo of Sarvan Singh Gill

Sarvan Singh Gill

  • 9 Posts
  • 0 Reply Likes
thanks jessse ....