gpt4 book ai didi

javascript - Ajax轮询获取返回数据对象的url未找到

转载 作者:行者123 更新时间:2023-12-03 04:15:18 25 4
gpt4 key购买 nike

我正在尝试执行 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

最佳答案

$.get({url: '../includes/polling.php?id=' + enquiryId}) 更改为 $.get('../includes/polling .php?id=' + enquiryId)

url 直接作为 .get() 的第一个参数

关于javascript - Ajax轮询获取返回数据对象的url未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44167074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com