
setInterval(function(){
jQuery.ajax({
type:"POST",
url:"111.php",
global:false,
dataType:"json",
data:"action=ajax",
success:function(data){
jQuery("p").html(data.shopid)
},
error:function()
{
alert("err: *** 作错误")
}
})
}, 2000)
php部分更简单
if($_POST['action']=='ajax'){
$result=$db->get_one("select * from shtq_shop order by rand() limit 1")
echo json_encode($result)exit
}
原理很简单 setInterval() 定时执行一个ajax,后台部分执行数据库查询 获得json格式数组
通过回调函数将返回的内容插入到<p></p>中
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)