我是AJAX的新手,我正试图从数据库中获取一些关于shoutbox的消息。这是我的AJAX脚本:
var chatUpdate = function() {
$.ajax({
url: "/getChat",
success: function(data) {
// do something with "data"
if (data.length > 0) {
var page = $(data);
var time = page.find('#time').val();
console.log(time);
var now = Math.round((new Date()).getTime() / 1000);
if(now >= time){
var statusText = page.find('#msg').val();
console.log(statusText);
$("#chatTable").append(statusText);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
};
setInterval(chatUpdate, 25000);
以及PHP获取数据后的作用:
echo "<div id='msg'><tr><td>" .$row['username']. "<hr style='margin:0; padding: 0;' />" .$row['msg']. "</td></tr></div> <div id='time'>".$row['time']."</div>";
但是,在控制台中它表示statusText或time都没有值。造成这种情况的原因是什么,因为数据库中确实存在数据。