Jquery异步提交表单数组元素

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ygc123189/article/details/71087752

今天修改功能的时候,遇到必须Jquery异步提交表单数组元素。

代码如下:

        

    <input type='hidden' name='address_id' id='address_id' value='0'>

    <input type='hidden' name='buyer_mobile' id='buyer_mobile' value='0'>
    <foreach name="is_checkout" item="id">
    <input type="hidden" name="is_checkout[]" class="is_checkout" value="{$id}" />
    </foreach>

form里有很多的表单元素,其中一个是数组类型,而且不是所有的表单元素都要提交。

$(“form”).serialize();可以实现提交表单数组的要求。

灵活变通一下,$("#address_id,.is_checkout").serialize(),就可实现自定义提交表单元素。

    $.ajax({
        url: "{:U('order/ajax_order_check')}",
        type: 'post',
        dataType: 'json',
        data: $("#address_id,.is_checkout").serialize(),
        success:function(d){
            if(d.status==1){
					$("#order-form").submit();
            }else{
                $.Alert(d.msg,200,6000);
            }
            self.val("审核无误提交")
            ajax_status=true;
        },
        error:function(xhr,type,errorThrown){
            ajax_status=true;
            self.val("审核无误提交")
            $.Alert("网络故障")

        }
    }) 

猜你喜欢

转载自blog.csdn.net/ygc123189/article/details/71087752
今日推荐