简体   繁体   English

jQuery $ .post回调触发一个永不结束的函数

[英]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. 我正在对接收MVC部分页面的服务器进行回调。 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; 在其中,我正在检查一个特定的属性(使用data-的自定义属性),该属性也很有效; 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 ": 这是所谓的函数“ 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 编辑:每个请求,这是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. 有一阵子,我以为jquery崩溃正在崩溃,但是放一个简单的alert('test')告诉我发生了什么。 It just was never finishing. 只是从未完成。

Are there specific lengths of time a callback function can be called from a jquery postback? 是否可以从jquery回发中调用回调函数有特定的时间长度? 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. 我正在模式视图中加载所有内容,这表明“哦,也许jquery被包含了两次”,但是我在其他方面已经遇到了这个问题,并确保只包含一次。 As in the include is only once in the entire app and the layout is only applied to the main page. 如在include中,在整个应用程序中只有一次,并且布局仅应用于主页。

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. 我有一个有时被设置为undefined的变量,导致它默默崩溃。 I have no idea why there was no error message. 我不知道为什么没有错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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