getJSON请求问题(静态页面调用动态数据)返回的JSON数据需要在HTML页面容器循环出来! 50
JS页面:$(document).ready(function(){varhotels_name=$('#hotels_name').text();alert(hotel...
JS页面:
$(document).ready(function(){
var hotels_name=$('#hotels_name').text();
alert(hotels_name);
/* $.getJSON("http://localhost/chinahotelsmap/control/getHotelRoomPrice.php?hotels_name="+hotels_name+"&jsoncallback=?", function(data){
if(data.length>0){
for( i=0;i<= data.length);i++){
$('#hotels_type_name'.val(data.hotels_type_name));
$('#hotels_price'.val(data.hotels_price));
}
}else{
alert('未取得酒店数据!')
}
});*/
});
PHP请求页面:
$hotels_name=@$_REQUEST['hotels_name'];
//echo $hotels_name;return;
$sql="select hotels_type_name,hotels_price from hotels join hotels_type on hotels.hotels_type_id=hotels_type.hotels_type_id where hotels_name='$hotels_name'";
$res=mysql_query($sql);
$num=mysql_num_rows($res);
if($num>0){
while($row=mysql_fetch_array($res,MYSQL_BOTH)){
$hotels_type_name=$row['hotels_type_name'];
$hotels_price= $row['hotels_price'];
$jsondata = "{hotels_type_name:'".$hotels_type_name."',hotels_price:'".$hotels_price."'}";
//echo $jsondata ;
echo $_GET['callback'].'('.$jsondata.')';
}
}
代码是错误的 求个高手给改改! 展开
$(document).ready(function(){
var hotels_name=$('#hotels_name').text();
alert(hotels_name);
/* $.getJSON("http://localhost/chinahotelsmap/control/getHotelRoomPrice.php?hotels_name="+hotels_name+"&jsoncallback=?", function(data){
if(data.length>0){
for( i=0;i<= data.length);i++){
$('#hotels_type_name'.val(data.hotels_type_name));
$('#hotels_price'.val(data.hotels_price));
}
}else{
alert('未取得酒店数据!')
}
});*/
});
PHP请求页面:
$hotels_name=@$_REQUEST['hotels_name'];
//echo $hotels_name;return;
$sql="select hotels_type_name,hotels_price from hotels join hotels_type on hotels.hotels_type_id=hotels_type.hotels_type_id where hotels_name='$hotels_name'";
$res=mysql_query($sql);
$num=mysql_num_rows($res);
if($num>0){
while($row=mysql_fetch_array($res,MYSQL_BOTH)){
$hotels_type_name=$row['hotels_type_name'];
$hotels_price= $row['hotels_price'];
$jsondata = "{hotels_type_name:'".$hotels_type_name."',hotels_price:'".$hotels_price."'}";
//echo $jsondata ;
echo $_GET['callback'].'('.$jsondata.')';
}
}
代码是错误的 求个高手给改改! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询