function start(){
$('#detailsPage').live('pageshow', function(event) {
var user_name = getUrlVars()["user_name"];
//var user_name = "studentB";
$.getJSON('http://mydomain.com/getStudent.php?user_name='+user_name+'&jsoncallback=?', displayStudent);
});
}
上面是js,下面是php
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Content-type: application/json");
include('mysqlConfig.php');
$user_name = $_GET["user_name"];
$sql="SELECT * FROM tbl_user WHERE user_name='$user_name'";
$result=mysql_query($sql);
$rows = array();
//retrieve and print every record
while($r = mysql_fetch_assoc($result)){
// $rows[] = $r; has the same effect, without the superfluous data attribute
$rows[] = array('data' => $r);
}
// now all the rows have been fetched, it can be encoded
//echo json_encode($rows);
$data = json_encode($rows);
echo $_GET['jsoncallback'] . '(' . $data . ');';
?>
我想知道这种方法是否有效?在我的应用程序中,第 n 个是显示。我不确定 jsoncallback 值是否被错误地实现。您的意见将有很大帮助。谢谢