页面表单提交后令页面不跳转,并获取返回数据

当我们做表单提交后,页面会进行跳转,有的需求是不希望页面跳转,解决方方法如下:

1.在页面上body下嵌套 <iframe>,代码如下:


 <iframe  id="submitFrame" style="display: none;width:0; height:0" name="submitFrame"  src="about:blank"></iframe>

2.form表单上绑定iframe的id号。

  <form id="themeForm" action=" "  method="post"  target="submitFrame"  enctype="multipart/form-data" >
3.获取跳转页面上的数据

 我的解决方法是 引入 jq 的 ajaxForm,调用里面的ajaxForm()方法

$("#themeForm").ajaxForm(function(data){ 
  themeImgName = data.results[0].filePath ;
  themeImgName = themeImgName.split('/').pop();
  alert(themeImgName);
  });

  接收的data值就是表单提交返回的数据。

猜你喜欢

转载自blog.csdn.net/a4171175/article/details/80466073