我想传递一个表,该表的数据是使用JSON数组从数据库中获取的。如何在JSON_ENCODE
的message参数中传递它 function check_order(){
var mob= $('#order-status-input').val();
if (/^[0-9]{1,10}$/.test(+mob) && mob.length==10){
document.getElementById('check_status_conf').style.display="block";
$.getJSON("status.php", {mobile:mob},function(data){
if(data['status']==1){
document.getElementById('check_status_conf').innerHTML=data['message'];
}
else if(data['status']==2){
document.getElementById('check_status_conf').innerHTML=data['message']
}
});
}
};
这是PHP -
<?php
$mobile = $_GET['mobile'];
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("XXXXX", $connection);
$query = mysql_query("select id,order_date,status from tbl_orders where mobile=$mobile");
$r=mysql_num_rows($query);
if($r >= 1)
{
$mess=while($rw=mysql_fetch_array($query))
{?>
<table>
<tr><td><?php echo "".$rw['id'];?><br /></td><td><?php echo "".$rw['order_date'];?><br /></td><td><?php echo "".$rw['status'];?><br /></td></tr>
</table>
<?php
}
echo json_encode(array('status'=>1,'message'=>$mess));
}?>