简体   繁体   中英

JQuery $.post callback firing a function that never finishes

Here's the problem. I'm making a callback to the server that receives an MVC partial page. It's been working great, it calls the success function and all that. However, I'm calling a function after which iterates through specific elements:

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

Inside this, I'm checking for a specific attribute (custom one using data-) which is also working great; however; the iterator never finishes. No error messages are given, the program doesn't hold up. It just quits.

Here's the function with the iterator

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"); 
}

Here's the function called in that, " 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;
    }


}

This is the way the attribute appears

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

EDIT: Per request, here is the 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
    });

For a while, I thought the jquery collapse was breaking, but putting the simple alert('test') showed me what was happening. It just was never finishing.

Are there specific lengths of time a callback function can be called from a jquery postback? I'm loading everything in modal views which would indicate "oh maybe jquery is included twice", but I've already had that problem for other things and have made sure that it only ever includes once. As in the include is only once in the entire app and the layout is only applied to the main page.

I'm open to any possibilities.

Thanks!

~Brandon

Found the problem. I had a variable that was sometimes being set as undefined cause it to silently crash. I have no idea why there was no error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM