簡體   English   中英

jQuery $ .post回調觸發一個永不結束的函數

[英]JQuery $.post callback firing a function that never finishes

這是問題所在。 我正在對接收MVC部分頁面的服務器進行回調。 它一直都很棒,它調用了成功功能等等。 但是,我要調用一個函數,之后要遍歷特定元素:

$(".tool-fields.in div.collapse, .common-fields div.collapse").each(...)

在其中,我正在檢查一個特定的屬性(使用data-的自定義屬性),該屬性也很有效; 然而; 迭代器永遠不會完成。 沒有給出錯誤信息,該程序沒有停止。 它只是退出。

這是迭代器的功能

function HideShow() {
    $(".tool-fields.in div.collapse, .common-fields div.collapse").each(function () {


    if (IsDataYesNoHide(this)) {

        $(this).collapse("show");

    }
    else
        $(this).collapse("hide");
    });

    alert("test"); 
}

這是所謂的函數“ IsDataYesNoHide ”:

function IsDataYesNoHide(element) {
    var $element = $(element);
    var datayesnohide = $element.attr("data-yes-no-hide");
    if (datayesnohide !== undefined) {
        var array = datayesnohide.split(";");
        var returnAnswer = true;

        for (var i in array) {
            var answer = array[i].split("=")[1];

            returnAnswer = returnAnswer && (answer.toLowerCase() === "true");

        }
        return returnAnswer;
    }
    else {
        return false;
    }


}

這是屬性出現的方式

data-yes-no-hide="pKanban_Val=true;pTwoBoxSystem_Val=true;"

編輯:每個請求,這是jquery $ .post

$.post(path + conPath + '/GrabDetails', $.param({ data: dataArr }, true), function (data) {
        ToggleLoader(false); //Page load finished so the spinner should stop

        if (data !== "") { //if we got anything back of if there wasn't a ghost record
            $container.find(".container").first().append(data); //add the content
            var $changes = $("#Changes"); //grab the changes
            var $details = $("#details"); //grab the current

            SplitPage($container, $details, $changes); //Just CSS changes

            MoveApproveReject($changes); //Moves buttons to the left of the screen
            MarkAsDifferent($changes, $details) //Adds the data- attribute and colors differences


        }
        else {
            $(".Details .modal-content").removeClass("extra-wide"); //Normal page
            $(".Details input[type=radio]").each(function () {
                CheckOptionalFields(this);
            });
        }

        HideShow(); //Hide or show fields by business logic
    });

有一陣子,我以為jquery崩潰正在崩潰,但是放一個簡單的alert('test')告訴我發生了什么。 只是從未完成。

是否可以從jquery回發中調用回調函數有特定的時間長度? 我正在模式視圖中加載所有內容,這表明“哦,也許jquery被包含了兩次”,但是我在其他方面已經遇到了這個問題,並確保只包含一次。 如在include中,在整個應用程序中只有一次,並且布局僅應用於主頁。

我樂於接受任何可能性。

謝謝!

〜布蘭登

找到了問題。 我有一個有時被設置為undefined的變量,導致它默默崩潰。 我不知道為什么沒有錯誤消息。

暫無
暫無

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

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