0

Below code works correct on server, but not locally. I don't use localhost, i just open html file in firefox. I need to make it works like that because this is for phone app (phonegap) and it wont be upload to any server.

jQuery library is loaded correclty.

    $.ajax({
        type: "GET",
        url: "http://www.mydomain.co.uk/test-login.php",
        data: { curPage: 153 }
    }).done(function( msg ) {
        $('body').html( msg );
    });
miszczu
  • 1,179
  • 4
  • 19
  • 39
  • 2
    possible duplicate of [JQuery ajax cross domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) – fsw Jul 15 '13 at 10:34

1 Answers1

1

For security reasons, AJAX will not work when used on different domains. Like from site1.com to site2.com. So when you tried to access your online website via localhost, you will see an error in your web inspector. To make it work on phonegap, you will have to whitelist the website in your config.xml
http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

Jereme
  • 621
  • 6
  • 14
  • thank for hint, i know about it. but i had a problem with ajax at all, not only on mobile device – miszczu Jul 15 '13 at 10:47
  • Yes. Ajax cannot work on cross domain when in the browser. Like you cannot access yoursite.com in ajax when you are in your localhost. You have to be in yoursite.com. Anyway I think this has a similar topic http://stackoverflow.com/questions/15628016/make-ajax-call-cross-domain . One post suggested the use of YQL – Jereme Jul 15 '13 at 11:22