0

I am trying to build an "app version" of my website (a social network). I am using PhoneGap + jQuery Mobile (i started learning them today).

The app simply needs to retrieve new posts from the website and show them to the user. Therefore I thought a simple Ajax Request would do the job. So, i created a php test file on the server (URL: http://www.racebooking.net/it/moto/app/get_post_test.php), which simply Echoes Alien contact SUCCESS!

I've made a simple html page in localhost (on my PC) called index.html with a div called #post-container and an AJAX request:

var root = "http://www.racebooking.net/it/moto"
$.get(root + "/app/get_post_test.php", function(data){
    $("#posts-container").html(data);
});

If everything is correct, i expect to see Alien contact SUCCESS! in the post-content div. What happens looks strange:

  • If i run the app from eclipse using Genymotion, everything works fine and i see the message Alien contact SUCCESS! -> the AJAX request went fine
  • If i open the index.html file on firefox, i don't see anything and FireBug informs me that the cross-origin request was blocked. He also tells me to activate CORS.

1) Why is that happening and how can i make FireBug work (which is better and faster for debugging)?

2) Am i following the right procedure or i am missing something?

Alberto Fontana
  • 928
  • 1
  • 14
  • 35

1 Answers1

0

I found the solution from this post.

I just needed to add header('Access-Control-Allow-Origin: *'); at the top of my php file.

Community
  • 1
  • 1
Alberto Fontana
  • 928
  • 1
  • 14
  • 35