Phonegap jQuery ajax request does not work

前端 未结 1 1177
南笙
南笙 2020-12-10 09:45

I want to develop a Phonegap application and I am using jQuery Mobile. I am developing and testing via Firefox on the PC, so the issues described here don\'t have anything t

相关标签:
1条回答
  • 2020-12-10 10:37

    Okay, so there are a number of things going on here. First Firefox won't allow you to do a cross domain request using AJAX so that is why you are getting the error case when you try it from your desktop browser.

    If you were testing on the device I would suspect that jQuery would be giving your a successful result. You see when running code from the file:// protocol on a mobile device the same origin policy does not apply. In fact I've done an AJAX query to that exact Google API in a sample app I developed with PhoneGap.

    However, depending on the version of jQuery you are using there may be a bug. Frequently when you do an AJAX request from the file:// protocol the xhr.status coming back will be '0'. That is actually okay and should be treated the same as a '200' but I believe older version of jQuery have an issue with the 0 status.

    I've written a quick blog post on doing XHR from a PhoneGap application that you can read:

    http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html

    It takes jQuery completely out of the equation. If that doesn't work then nothing will.

    0 讨论(0)
提交回复
热议问题