簡體   English   中英

jQuery ajaxForm有時有時可以完成,但有時僅觸發本地javascript函數,然后停止

[英]jQuery ajaxForm complete works sometimes, other times it only fires a native javascript function then stops

這可能是該主題的重復,但是我必須復活它,因為我的問題似乎比這更深。 我目前正在使用ajaxForm()向PHP腳本提交4個問題測驗,接收結果,然后將其填充回DIV中。 觸發beforeSend函數,將信息發送到ajax.php腳本。 beforeSend還顯示了測驗容器中的加載圖形。 然后,當ajax.php返回要填充到DOM中的HTML時, complete函數將正確觸發。 到那時,一切都停止了。 下一行是對slideUp上載div的調用,然后在quizContainer中顯示返回的信息。

在這一點上,如果我輸入了JavaScript alert它將始終觸發,這意味着complete至少應在應觸發的時間觸發,但對加載div的jQuery引用將被完全忽略。 這是處理提交的javascript文件的代碼-處理此部分的部分是“處理測驗提交”:

$(document).ready(function () {
// Get rid of the message box after 15 seconds
setTimeout(function() {
    $('#message').slideUp('fast');
}, 10000);

// Handle the Course List LIs
$('#courseList li').on('click', function () {
    // Get the background color as it's set initially
    var color = $(this).attr('oColor');
    jQuery('div', this).toggle('slow', function () {
        if ($(this).is(":hidden")) {
            $(this).css('background-color', color);
        }
    });

    // Change the background to be the same as the content background when it's expanded
    if ($(this).is(":hidden")) {
        $(this).css('background-color', '#33CC66');
    } else {
        $(this).removeAttr('style');
    }
});

// Handle the quiz submission
jQuery.fn.exists = function(){return this.length>0;}
if ($('#quizForm').exists()) {
    $('#quizForm').ajaxForm({
        beforeSend: function() {
            $('#quizContainer').slideUp('fast', function () {
                $('#loading').show();
            });
        },
        complete: function(xhr, theStatus) {
            alert(theStatus);
            $('#loading').slideUp('fast', function () {
                $('#quizContainer').html(xhr.responseText);
                $('#quizContainer').show();
            });
        }
    });
}

});

如有必要,我可以提供更多信息,如果有人希望看到它的使用,可以提供一個臨時登錄信息來訪問它。 我目前正在使用jQuery 1.8.1(。)

謝謝你的幫助! 喬恩

我相信complete函數的第一個參數是xhr.responseText而不是實際上是第三個參數的xhr對象。 嘗試從您的complete:函數中刪除.responseText

暫無
暫無

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

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