ajax提交form表单带文件

form表单代码:

	<form class="reg_box clearfix" action="" method="post" name="myForm" id="myForm" data-uri="{:url('ajaxCheckUser')}">	

ajax代码:

var form = new FormData(document.getElementById("myForm"));
                $.ajax({
                    type :"post",
                    url : "{:url('home/user.login/regDo')}",
                    data : form,
                    processData:false,
                    //告诉jQuery不要去设置Content-Type请求头,因为表单已经设置了multipart/form-data
                    contentType:false,
                    success :function (res) {
                        if(res.status==0){
                            layer.closeAll();
                            layer.msg(res.msg);
                            return false;
                        }else{
                            layer.msg(res.msg,{icon:1,time:2000,end:function () {
                                    layer.closeAll();
                                    $(location).attr("href","/home/user.login/secondReg.html");
                                }});
                        }

                    }
                })

重点:

processData:false contentType:false 这两个必须

你可能感兴趣的:(PHP)