我有一个简单的PHP,下面有一个HTML文件(这是phonegap-index.html页面提供的文件),它包含一些jQuery代码以从PHP获取内容,在本地主机上。在浏览器中一切正常,但在phonegap中,我只能看到html代码,也就是说,我没有看到通过jQuery接收到的内容。我已将我的IP地址和本地主机添加到phonegap的config.xml文件中用于列入白名单。 jQuery回调被设置为JSONP。 Phonegap服务器安装在运行良好的ubuntu上,iPhone 5s上安装了PhoneGap应用程序/客户端,它显示了任何简单的html内容,但没有通过jQuery接收到php内容。Phonegap无法显示通过jQuery检索到的php内容
我相信问题是phonegap,但我花了三天的时间,并找不到我做错了什么。
这里是我的文件: 的index.html
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<!-- jQuery to get data from gettext.php page -->
<script>
$(document).ready(function(){
$.getJSON('http://localhost/hello/gettext.php', function(jsonp){
$("#txtHint").html(JSON.stringify(jsonp, null, 2));
});
});
</script>
</head>
<body>
<br /><br /><br />
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript">
app.initialize();
</script>
<!-- this section is populated by jQuery -->
<p>php content received via jQuery: <span id="txtHint"></span></p>
</body>
</html>
这是我gettext.php页
<?php
header('content-type: application/jsonp; charset=utf-8');
header("Access-Control-Allow-Origin: *");
echo json_encode("Hello World!");
?>
以下是config.xml文件中的特定部分的白名单
<access origin="*" />
<access origin="http://127.0.0.0/hello2/gettext.php" />
<access origin="http://localhost/hello2/gettext.php" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://localhost/hello2/gettext.php" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
感谢您的回答山姆。我可以从iPhone浏览器访问我的机器上的本地主机,但如果我使用IP地址192.168.0.9,则可以从我的iPhone访问gettext.php。这个问题对我来说没有意义,因为我的iPhone浏览器中显示的是我的PHP文件的HTML内容显示在我的iPhone浏览器中,但是通过jQuery检索到的PHP消息被忽略了?如果我可以从iPhone上看到托管在我的本地主机服务器上的HTML内容,那么为什么不显示PHP消息。 – noviceAppDev