ajax表单提交

ajax表单提交

html代码示例

<form action="{:url('')}" method="post" id="ajax_form"  >
<button type="button" id="btn">保存</button>
</form>

js代码

//ajax表单提交
    $("#btn").on('click', function() {
        var action = $('#ajax_form').attr('action');
        $.ajax({
            type: "post",
            url: action,
            data: $("#ajax_form").serialize(),
            success: function(data) {
                if (data.code==1){
                    return alert(data.msg);
                }else{
                    return  alert(data.msg);
                }
            },
            error: function(data) {
                return  alert(data.msg);
            }
        })
    });



回复列表


回复操作