以前都是通过ajax像后台传送数据,新接触了个form.js向后台提交数据的方式(付源码)

来源:互联网 发布:手机自动播音软件 编辑:程序博客网 时间:2024/05/29 03:06
实现原理是这样的:
他是通过一个input--file按钮,通过监听file文件的change属性,去做form表单提交的,我们知道当单纯的用form表单提交的时候,提交成功后都会跳转页面,那form.js就是阻拦了跳转页面,从而在succsee里面来接受form提交后接受的参数的。
js
//异步提交表单
$("#filer").on("change",function(){
console.log($(this));
$("#formid").ajaxSubmit({
type:'post',
dataType:'json',
xhrFields: {
withCredentials: true
},
crossDomain: true,
url:url+"equipmentInfo/inportExcel.do",
success:function(data){
// var data = JSON.parse(data)
// alert(data.data.userHeadImg);
console.log(data);
} else{
// window.location.reload();
}
// window.location.reload();
// $(".touxiang_imgs").attr("src",data.data.userHeadImg) ;
// window.localStorage.setItem("userHeadImg",data.data.userHeadImg)
},
error:function(XmlHttpRequest,textStatus,errorThrown){
console.log(XmlHttpRequest);
console.log(textStatus);
console.log(errorThrown);
}
});

});



html

<form id='formid'>

<input type='file' id='filer'/>

</form>

0 0
原创粉丝点击