2015-08-17 37 views
0

例如,我目前在/用戶頁面,當我從該頁面發送請求是指/用戶/會話/ ID,而我只需要交談/ ID。如何做?如何繞過Ajax中GET請求方法的當前頁面?

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

+0

前面你想要的絕對路徑。 – SLaks

+0

@PatrickEvans創建一個答案,我可以接受它 –

+0

@PatrickEvans你幫了我,謝謝 –

回答

1

您使用的是相對路徑:"conversations/" + conversation_id,相對路徑將獲得附加到當前路徑。

您想改爲使用絕對路徑。既然你要/conversations/id只需添加/到您的路徑

$.get("/conversations/" + conversation_id