Ajax.actionlink And Confirm Dialog
Solution 1:
As per: Javascript Alertify with return from confirm
Alertify is a non blocking code and it returns before user makes a response. Use fiddler or firebug to see the timeline of user's choice and ajax request.
functionMyConfirm() {
alertify.confirm("Do you really want to do that??", function (e) {
if (e) alert('after they pressed confirm, but ajax is already sent');
elsealert('after they pressed confirm, but ajax is already sent');
});
// no return here
}
According to http://yassershaikh.com/how-to-use-onbegin-method-with-ajax-beginform/ returning false should cancel Ajax call. but your function does not return anything at the moment.
So the answer by Nicholas is probably the only correct one.
In response to your comment. Assuming you know how to block execution of js (which is a horrible thing to do! and you should not!) this will do the trick for you:
// this tells us if use made a choicevar userClicked = false;
// this is for user's choicevar userChoice;
functionMyConfirm() {
alertify.confirm("Do you really want to do that??", function (e) {
// mark that user clicked
userClicked = true;
if (e) {
userChoice = true;
} else {
userChoice = false;
}
});
// Put your delay code here // userClicked tells you that user made a choice// Remember that setTimout will fail here as it's a fork, not a blocking function// you will have to do some crazy while loops that will make unicorns cry
userClicked = false;
return userChoice;
}
Solution 2:
I haven't used alertify
, but from the method signature, I presume that alertify.confirm
returns immediately and runs the callback method when the user closes the popup some time later.
This means that your MyConfirm
method also returns immediately, and if it does not return false, the ajax call is started.
You can fix this by always returning false
from MyConfirm
, and only making the ajax call in your alertify.confirm
callback function:
functionMyConfirm() {
alertify.confirm("Do you really want to do that??", function (e) {
// this actually makes the ajax call if requiredif (e) doAjaxCall();
});
returnfalse;
}
Post a Comment for "Ajax.actionlink And Confirm Dialog"