gpt4 book ai didi

javascript - 如何在Ajax中绕过GET请求方法的当前页面?

转载 作者:行者123 更新时间:2023-12-03 09:11:45 25 4
gpt4 key购买 nike

例如,我当前位于 /users 页面上,当我从该页面发送请求时,它会在我需要时引用 /users/conversations/id只是对话/id。如何做到这一点?

users.js

$('.start-conversation').click(function (e) {
e.preventDefault();

var sender_id = $(this).data('sid');
var recipient_id = $(this).data('rip');

$.post("/conversations", { sender_id: sender_id, recipient_id: recipient_id }, function (data) {
chatBox.chatWith(data.conversation_id);
});
});

chat.js

   $.get("conversations/" + conversation_id, function (data) {
$('#chatbox_' + conversation_id).html(data);
$("#chatbox_" + conversation_id + " .chatboxcontent").scrollTop($("#chatbox_" + conversation_id + " .chatboxcontent")[0].scrollHeight);
}, "html");

enter image description here

最佳答案

您正在使用相对路径:“conversations/”+conversation_id,相对路径将附加到当前路径。

您想使用绝对路径。由于您想要 /conversations/id,只需将 / 添加到路径的前面

$.get("/conversations/" + conversation_id

关于javascript - 如何在Ajax中绕过GET请求方法的当前页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32057802/

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