Home > Backend Development > PHP Tutorial > $.getJSON()访问time.php页面,time.php页面返回数据

$.getJSON()访问time.php页面,time.php页面返回数据

WBOY
Release: 2016-06-20 12:38:19
Original
1128 people have browsed it

index.htm 页面:

function updateTime(){
$.getJSON("time.php", 
function(data){
alert(data);
now = data.time;
}
);

}

time.php页面:
{"time":1454237138} //返回某一时间, 1454237138表示秒数

现在我的问题是:{"time":1454237138}需要改为返回当前时间,而不是返回固定一个时间。


回复讨论(解决方案)

time.php页面
echo json_encode(array('time' => time()));

time.php页面:

echo json_encode(array('time' => time()));
?>
版主大人是这样嘛?但是还是没结果,是不是返回的json格式不对,请指教

time.php页面
echo json_encode(array('time' => time()));

还是没结果,我的time.php页面:
echo json_encode(array('time' => time()));
?>


time.php页面
echo json_encode(array('time' => time()));

还是没结果,我的time.php页面:
echo json_encode(array('time' => time()));
?>
你试试alert(data.time)看看有什么结果?



time.php页面
echo json_encode(array('time' => time()));

还是没结果,我的time.php页面:
echo json_encode(array('time' => time()));
?>
你试试alert(data.time)看看有什么结果? 没什么反应

你可以打开浏览器调试功能,看看发出去的请求有没有成功

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template