我在user.php页面中使用了一个轮询脚本,它使用长轮询JS从upsidenew.php页面获取新事件(if)。
现在我的问题,为什么我的脚本显示返回结果:function detail(){[native code]}
请参阅下面的代码;这是我完整的民意调查代码。
我的Sql表名称:updateside
id - work_id - parent_id - from_id - to_id - sub - detail - img - created
..........................................................................
AI - work_id, parent_id etc. all data collect by user post form
在我的upsidenew.php页面中:
$parent = $row['parent_id']; // collect from above query
date_default_timezone_set('Asia/Dhaka');
$timestamp = date("M j, y; g:i a", time() - 2592000);
$u = mysqli_query($dbh,"SELECT * FROM updateside WHERE `parent_id`='".$parent."' AND `created` > '".$timestamp."' ORDER BY created DESC") or die(mysqli_error($dbh));
while ($row = mysqli_fetch_array($u)) {
$result['from_id'] = $row['from_id'];
$result['parent_id'] = $row['parent_id'];
$result['detail'] = $row['detail'];
.....
...
header('Content-Type: application/json');
echo json_encode($result);
exit;
}
在user.php页面上我的JavaScript:
function waitForMsg(){
$.ajax({
type: "GET",
url: "upsidenew.php",
async: true,
cache: false,
timeout:50000,
datatype: 'json',
success: function(data){
if(data) {
$("#updatetime").html('<div class="upbox1" id=" '+ parent_id + '"> ' + data.detail + '</div>');
}
setTimeout(
waitForMsg, /* Request next message */
1000 /* ..after 1 seconds */
);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
addmsg("error", textStatus + " (" + errorThrown + ")");
setTimeout(
waitForMsg, /* Try again after.. */
15000); /* milliseconds (15seconds) */
}
});
}
$(document).ready(function () {
waitForMsg(); /* Start the inital request */
});