如何从js中的子节点返回false到父事件

时间:2015-09-07 07:48:41

标签: javascript jquery ajax callback

这是我的js代码:

$(function () {
    $('#buyer').on('submit', function (event) {
        var userCaptcha = $('#jCaptcha').val();
        $.post('Jcaptcha', {
            jcaptcha: userCaptcha
        }, function (responseText) {
            if (responseText !== "") {
                $('#ajaxcall').html(responseText);
                //return from here
            }
        });
    });
});

我想将false返回给我的提交事件,以便不能提交表单。

1 个答案:

答案 0 :(得分:0)

您可以使用event.preventDefault();阻止表单首先提交,而不是在ajax回调中提交。您的实际提交必须通过ajax处理 - 我认为这是您$.post中发生的事情。

$(function () {
  $('#buyer').on('submit', function (event){
    event.preventDefault(); // dont actually submit natively
    var userCaptcha = $('#jCaptcha').val();
    $.post('Jcaptcha', { jcaptcha : userCaptcha }, function (responseText) {
        if (responseText !== "") {
            $('#ajaxcall').html(responseText);            
        }
    });
  });
});
相关问题