简体   繁体   English

jquery.load()在phonegap上不起作用

[英]jquery.load() not working on phonegap

I am developing buyers guide app with phonegap. 我正在使用phonegap开发买家指南应用程序。 where i am trying to fetch some info from server using jquery. 我在哪里尝试使用jquery从服务器获取一些信息。 but when i run following code with phonegap its not working 但是当我使用phonegap运行以下代码时,它不起作用

<!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>

Do you have CORS enabled on the server? 您在服务器上启用了CORS吗?

PhoneGap loads the index.html from the local filesystem and the same origin policy prevents ajax calls to different domains, such as localhost. PhoneGap从本地文件系统加载index.html,并且相同的原始策略可防止对不同域(例如localhost)的ajax调用。

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 您不能在设备上使用localhost,因为localhost是设备,而必须使用服务器本地IP

And you have to whitelist the IP too (or use *, it whitelist all the IPs) whitelist guide 而且您也必须将IP列入白名单(或使用*,它将所有IP 列入白名单白名单指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM