开发者

Trigger event after event.preventDefault

I'm catching clicks on submit button of a form. I do event.preventDefault() to disable default browser action so I'm able to do my stuff after clicking to button. I this case I do AJAX call to server. By response from the server I want to choose if continue with form submission or do something else.

$inviteSubmitForm.find('input[name="accept"]').click(function(e){
    e.preventDefault()开发者_如何学JAVA;

    $.ajax({
        ...
        success  : function(data) {

            if (data.something) {
                ...
            } else {
                ...
            }

        }
    });
});

Problem with this is, that I'm unable to cast default action of clicked button, cos logic is in AJAX callback. So return true just end callback function - I cannot use this simple trick. Also moving e.preventDefault() is no-go, cos form gets submitted immediately.

Any ideas?


trigger to submit the form:

$inviteSubmitForm.find('input[name="accept"]').click(function(e){
    e.preventDefault();

    $.ajax({
        ...
        success  : function(data) {

            if (data.something) {
                // don't submit
            } else {
                $inviteSubmitForm.submit();
            }

        }
    });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜