ajax 提交表单

来源:互联网 发布:电视柜淘宝 编辑:程序博客网 时间:2024/06/01 09:04
<input type="button" target="iframe" value="修改信息" onclick="test()" style="margin-top: 5px" class="btn btn-info" />
 
function test() {    var username = $('#username').val();    var password = $('#password').val();    var name = $('#name').val()    var mobile = $('#mobile').val()    console.log("name==="+name)    if (username==null||username==""){        layer.msg("用户名不能为空!")        return false    }else if(password==null||password==""){        layer.msg("密码不能为空!")        return false    }else if(name==null||name==""){        console.log("...")        layer.msg("请输入管理员名字!")        return false    }else if(mobile==null||mobile==""){        layer.msg("请输入管理员手机号!")        return false    }    if(confirm("确认修改?")) {        var form = new FormData(document.getElementById("editAdmin"));        console.log("11111")        $.ajax({            url:'<%=base%>/ctl/admin/editAdmin',            dataType: 'json',            type:'post',            data:form,            processData:false,            contentType:false,            timeout:5000,            success:function (result) {                if (result.type=="success"){                    location.href = '<%=base%>/ctl/admin/adminInfoPage?id='+$('#id').val()+'&url=adminPage';                }else {                    Notify(result.content, 'top-right', '5000', 'danger', 'fa-desktop', true);                }            }        })    }else {        return false    }}
函数方法避免使用  关键字(delete,submit 等), 上传数据为对象,  必须 加上 contentType:false  否则会报错
原创粉丝点击