3

EDIT: Solution for JQuery Mobile + Phonegap AJAX Problems:

subdomains="true" property in config.xml is not working in phonegap 2.9.0, every request to a subdomain will return 200 but $.ajax won't fire the success function (and $.getJSON won't fire anyways). Also: Syntax *.domain.tld as stated in the official doc is not working, only way I found to solve that problem: Setting access origin and acces uri to "*" (all)

<access origin="*"/>
<access uri="*"/>

I'm working on a mobile application using the jQuery Mobile Framework and Phonegap. I've just added an AJAX request to my application which is used to get data from my webserver. The page is correctly loading but Android (4.1.2) never fires the AJAX event or never gets a request from the Webserver, in fact it's just hanging on the loading spinner.

Strange thing about this is, that I already use an AJAX request to the same server (but with different domain) that works perfectly fine:

$.getJSON("[...]checkupdate.php?callback=?", function(data){    
   [...]    
})

I've tried to do the second request with $.getJSON too and it worked on my computer but failed on Android. I started looking around for a solution and found out, that setting the cache to false in $.ajax might help so I rewrote my code but it's still not working.

$.ajax({
cache : false,
type: 'GET',
url: requestURL,
dataType: 'jsonp',
context: document.body,
success: function(data){
    [...]
}});

Is there anything else to do to get this to work?

cybrox
  • 250
  • 4
  • 17
  • http://bit.ly/124oJ3U – Selvin Jun 28 '13 at 13:38
  • @Selvin forgot to write that, I've already set the correct overrides. ($.mobile.allowCrossDomainPages and $.support.cors), disabled cache in request, whitelistet the domain in config.xml (and I'm using JSONP) anythig else I've missed? – cybrox Jun 28 '13 at 13:46
  • 1
    ok ... so one more thing http://stackoverflow.com/questions/11318703/access-control-allow-origin-error-at-android-4-1 – Selvin Jun 28 '13 at 13:46
  • Isn't this only needed if I use local files to send the request? Besides that, I'm really wondering why the exactly same code is working a few lines below... – cybrox Jun 28 '13 at 13:53
  • 1
    ideas: 1. Take a look at logout output for clues. 2. you might want to process the ajax complete callback to know if something went wrong (or if the ajax call was actually processed). – kctang Jun 28 '13 at 15:40
  • @kctang I've completed it and getting the Error: %callbackfunction% was not called (readyState = 4, status = parsererror [200]) – cybrox Jun 28 '13 at 20:17
  • @all Edited my post, setting access origin and access uri solved the problem... – cybrox Jul 01 '13 at 16:59
  • you should probably post your answer using "answer your own question" otherwise it will keep showing up as "unanswered" in stackoverflow. – sonjz Aug 12 '13 at 19:44
  • Really shoud do that, I was hoping someone would correct me and say that it's just a bad dream but it really looks like this bug was the problem. – cybrox Aug 13 '13 at 05:44

1 Answers1

0

I found a way to solve that problem. I noticed, that the subdomains="true" property in phonegap's config.xml is not working. (Phonegap 2.9.0). Every request to a subdomain will return status 200 but $.ajax won't fire the success function (and $.getJSON won't fire anyways). The syntax *.domain.tld as stated in the official doc isn't working for me either, only way I found to solve that problem was setting access origin and acces uri to "*" (all)

cybrox
  • 250
  • 4
  • 17