开发者

Ajaxify + Confirmation Dialog?

I'm using jQuery Ajaxify to ajaxify my forms. It has all the same callbacks as the standard $.ajax function. I'm trying to add in a standard Javascript confirm() dialog before the form gets submitted though. Problem is, as soon as you click the submit button, the ajax request goes through. How do I delay that until after the user makes a choice to confirm?

The scripts that are clashing are:

$('form').ajaxify({
        success: function(data, status, request) {
           开发者_Go百科 // do some stuff
        }
    })

Which just submits the form via ajax rather than the HTML way. And then this script:

$('#accept-form').submit(function(e) {
        return confirm('Are you sure you want to accept this bid?');
});

Which does pop up the dialog, but it doesn't really matter what you click because the form has already been submitted and sent.


look up the Ajaxify onStart method, I think putting the confirm there could work.

Personally, I'd use a modal window (many jQuery plugins out there, eg. jqModal) and onStart because that way everything is in your control. the JS confirm dialog can't be styled or the buttons can't be changed and you can't wire custom events to the ok/cancel buttons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜