簡體   English   中英

在本身是AJAX響應的視圖上使用ajaxForm插件

[英]Using ajaxForm plugin on view that is itself an AJAX response

我正在為我的站點構建消息傳遞系統。 郵箱是平坦的,即訪問收件箱或發送新郵件不會移至另一頁,它只是切換div。 當用戶單擊一條消息時,AJAX調用將用所選線程替換收件箱div。 在線程視圖內,有一個表單來回復消息。

一些問題:

  1. 從這個thread_view內部,它向嵌套在整個郵箱div中的div發送AJAX響應,我無權訪問其外部的文檔對象。 因此,我無法在此視圖之外操作div,例如接收AJAX beforeSend和Success消息的div。 我認為這可以通過某種.load()完成,盡管我不確定具體如何。

  2. 我的AJAX不會觸發。 我正在使用Ajax.Form()插件。 我認為這個問題可能與第一個問題有關,但我不能肯定地說。 我不確定如何開始對Ajax請求進行故障排除,因為控制台中沒有錯誤。

  3. 我想知道問題是否與以下事實有關:我試圖從本身是來自先前ajaxRequest的響應的視圖發送ajaxRequest,即該線程的整個視圖是同一js中以下結果的結果文件作為下一個請求:

     // compose a message function $('#send_message').on("click", function(e) { var send_message_options = { type: 'post', url: "/users/new_message", beforeSend: function() { //Display a loading message while waiting for the ajax call to complete $('#message').html("Sending message..."); }, // Hide form and display results success: function(response) { $('#message').html(response); } }; $('#message_form').ajaxForm(send_message_options); }); 

我的新AJAX請求,什么都不做:

$('#reply_in_thread').on("submit", function(e) {
e.preventDefault();
console.log("trying for reply");

var reply_options = {
    type: 'post',
    url: "/users/reply",
    beforeSend: function() {
        //Display a loading message while waiting for the ajax call to complete
        $('#reply_message').html("Sending message...");
    },
    // Hide form and display results
    success: function(response) {
        $('#reply_message').html(response);
    }
};

$('#reply_in_thread').ajaxForm(reply_options);

});

我不能說為什么ajaxForm()插件失敗,但是jquery $ .post成功了。 起作用的代碼如下:

$('#reply_in_thread').on("submit", function(e) {
e.preventDefault();   

var data = $(this).serialize();

$.post('/users/reply',data,function(response){
    $('#reply_message').html(response);
})

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM