當我們做表單提交后,頁面會進行跳轉,有的需求是不希望頁面跳轉,解決方方法如下:
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值就是表單提交返回的數據。