我正在尝试进行ajax轮询以刷新我的消息div但是我的控制台中出现以下错误:
http://localhost/~userb/grind/dashboard/[object%20Object] 404 (Not Found)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
n.(anonymous function) @ jquery.min.js:4
update_chat @ convo.js:8
jquery.min.js:4 GET
这是用于民意调查的片段JS:
setInterval(update_chat, 2000);
function update_chat()
{
var enquiryId = parseInt($('#messageMain').data('id'));
$.get({url: '../includes/polling.php?id=' + enquiryId})
.done(function(data) {
$('#messageMain').html(data);
});
}
html:
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-comment"></span> Chat
</div>
<div class="panel-body">
<ul class="chat" id="messageMain" data-id="<?= $to_id ?>"> <!-- $to_id is what is used to get the messages -->
<!-- all messages are queried from database here -->
</ul>
</div>
<div class="panel-footer">
<div class="input-group">
<input id="btn-input" type="text" class="form-control input-sm" data-to="<?= $to_id ?>" placeholder="Type your message here...">
<span class="input-group-btn">
<button class="btn btn-warning btn-sm" id="btn-chat">
Send</button>
</span>
</div>
</div>
</div>
Polling.php只是查询数据库并返回上面的html中使用的HTML
答案 0 :(得分:1)
将$.get({url: '../includes/polling.php?id=' + enquiryId})
更改为$.get('../includes/polling.php?id=' + enquiryId)
url直接作为.get()
的第一个参数