0

I am developing buyers guide app with phonegap. where i am trying to fetch some info from server using jquery. but when i run following code with phonegap its not working

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.9.1.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $('#div1').load('http://localhost/MySample.php');
  });
});
</script>
</head>
<body>

<div id="div1"><h2>Click to get information</h2></div>
<button>Get External Content</button>

</body>
</html>
NewCoder
  • 59
  • 1
  • 3

2 Answers2

0

Do you have CORS enabled on the server?

PhoneGap loads the index.html from the local filesystem and the same origin policy prevents ajax calls to different domains, such as localhost.

Vlad Stirbu
  • 1,732
  • 2
  • 16
  • 27
0

Are you testing on simulator or on a device?

You can't use localhost on a device because localhost is the device, you have to use the server local IP instead

And you have to whitelist the IP too (or use *, it whitelist all the IPs) whitelist guide

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • M using it on simulator. . Then hw cn I do it widout usin localhost? – NewCoder Feb 10 '13 at 20:34
  • If you are using the simulator, then localhost should work, so it has to be the whitelist problem. Look at the link I posted with the whitelist guide – jcesarmobile Feb 11 '13 at 07:44