0

我正在使用 jQuery 即兴库,但不了解它的异步性质。我在下面有一些代码,我想在提示运行后重定向。如果我的 data.redirectPage 语句为真,我不希望执行下一行代码。

               success: function (data) {
                    if (data.redirectPage == "hackathonregistration") {
                        $.prompt("Your code has been accepted and you will now be redirected to the hackathon registration page",
                        {
                            submit: function() {
                                window.location.href = "/Register/hackathon";
                            }
                        });
                    }
4

1 回答 1

0

从我快速阅读的有关Impromptu的内容来看,您的代码看起来不错。
除了缺少}关闭您的success功能... ;)

并且您尝试触发的提交上没有按钮。
这是一个重要的AND。

尝试这个 :

success: function (data) {
    console.log(data.redirectPage);
    if (data.redirectPage == "hackathonregistration") {
        $.prompt("Your code has been accepted and you will now be redirected to the hackathon registration page",
        {
            buttons: { "Yes": true, "No": false },
            submit: function(e,v,m,f) {
                // use e.preventDefault() to prevent closing when needed or return false.
                // e.preventDefault();
                console.log("Value clicked was: "+ v);
                if(v){
                    window.location.href = "/Register/hackathon";
                }
            }
        });
    }
}

v是布尔真/假。
就像说的那样,我在 Impromtu 上读得很快。

个人而言,我使用SweetAlert。寻找它作为替代...可能更容易。

于 2016-06-02T03:49:38.613 回答