0

我有一个表格,我试图实现它的 tinuy jquery ajax 代码。但问题是我使用 preventDefault() 来阻止表单自动提交。现在我不能让它提交,即使我想要它。

//after user clicks submit buttons
    $('.submit').click(function(event){
        data =  {
                    country: $('.country').val(),
                    tel_country_code: $('.country_code').val(),
                    tel_no: $('.tel_no').val()
                }

        $.ajax({
            type: 'POST',
            url: "<?php echo site_url('listings/does_business_exists');?>",
            data: data,
            dataType: "json",
            success: function(json_data){
                    if(json_data.result == false){
                        $('.error-position').html(json_data.errors);
                        $('.error-position').show();
                    }
                    else{
                        return true;
//i want form to submit here

                    }

            }

        });

        event.preventDefault();
    })

有什么建议的朋友吗??

4

4 回答 4

2

只需获取表格并提交即可

document.forms["formName"].submit();
于 2012-05-10T12:58:09.920 回答
0
$('.submit').click(function(event){
    var $this = $(this);

    data =  {
                country: $('.country').val(),
                tel_country_code: $('.country_code').val(),
                tel_no: $('.tel_no').val()
            }

    $.ajax({
        type: 'POST',
        url: "<?php echo site_url('listings/does_business_exists');?>",
        data: data,
        dataType: "json",
        success: function(json_data){
                if(json_data.result == false){
                    $('.error-position').html(json_data.errors);
                    $('.error-position').show();
                }
                else{
                    $this.parents('form:first').trigger('submit');
                }

        }

    });

    return false;
})
于 2012-05-10T12:58:17.650 回答
0

像这样添加,遍历文档,获取表单对象,然后在上面调用提交方法。检查此链接Document.forms

var obj= document.forms["yourForm"];
    obj.submit();
于 2012-05-10T12:58:53.600 回答
0

删除event.preventDefault();并尝试:

<form onsubmit = "return false;"> ... </form>
于 2012-05-10T13:00:35.747 回答