您可以使用PhoneGap的PHP和jQuery的Ajax获得的内容。在文件头加载jQuery库。在功能onBodyLoad(),
把Ajax调用的PHP文件:
$('#content').load('http://www.example.com/test.php');
在HTML会议,把DIV ID =“内容”你要显示的内容在哪里。
PHP:
for($i=1; $i<=10; $i++) {
echo '<p>Dinamic content coming from test.php! Value: ' . $i . ' of 10.</p>';
}
HTML会打印:
<p>Dinamic content coming from test.php! Value: 01 of 10.</p>
<p>Dinamic content coming from test.php! Value: 02 of 10.</p>
<p>Dinamic content coming from test.php! Value: 03 of 10.</p>
<p>Dinamic content coming from test.php! Value: 04 of 10.</p>
<p>Dinamic content coming from test.php! Value: 05 of 10.</p>
<p>Dinamic content coming from test.php! Value: 06 of 10.</p>
<p>Dinamic content coming from test.php! Value: 07 of 10.</p>
<p>Dinamic content coming from test.php! Value: 08 of 10.</p>
<p>Dinamic content coming from test.php! Value: 09 of 10.</p>
<p>Dinamic content coming from test.php! Value: 10 of 10.</p>
将内容发送到另一个页面和登录的用户,你可以像
$.get('login.php?name=user', function(data) {
$('#content').html(data);
});
和登录.php可能有这样的:
if (isset($_GET['name'])) {
$name = $_GET['name'];
echo "Name: $name";
} else {
echo "Please enter a valid name!!";
}
为了让您的登录安全,您可以使用POST方法,如下所述:
$('#form').submit(function() {
$.post('login.php', $('#form').serialize(), function(data) {
$('#content').html(data);
});
return false; // to avoid page going to login.php file
});
而且login.php中
if(!empty($_POST)) {
$user = $_POST['name'];
$pass = $_POST['password'];
// db query and stuff goes here...
echo "Worked!";
} else {
"Enter values!";
}
非常感谢狮子座。另一个问题;我如何能够以类似于上述描述的方式完成https请求?你有什么建议吗?再次感谢... – Pinchy