0

I'm using the jQuery impromptu library and not understanding the async nature of it. I've got some code below that I want to redirect after the prompt is run. I don't want the next line of code to execute if my data.redirectPage statement is true.

               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";
                            }
                        });
                    }
Peter Kellner
  • 14,748
  • 25
  • 102
  • 188

1 Answers1

0

From what I read fast about Impromptu, your code looks ok.
Except the missing } to close your success function... ;)

AND no buttons on the submit you try to trigger.
That is an important AND.

Try this :

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

I suppose v is the bolean true/false.
Like said, I read real fast on Impromtu.

Personnaly, I use SweetAlert. Look for it as an alternative... May be easier.

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64