鍍金池/ 問答/HTML/ form表單跨域提交在不使用jq的情況下能實現不跳轉頁面還能進行回調嗎??

form表單跨域提交在不使用jq的情況下能實現不跳轉頁面還能進行回調嗎??

關鍵詞:form跨域提交,不使用jq,不跳轉不刷新,拿到返回值

我現在要使用form表單來實現跨域提交,但是代碼中沒有引入jq(也不準備引入,jq中的ajaxForm和ajaxSubmit的方法是可以實現的),請問我怎么通過js來模擬這兩個方法,或者有其他更好的方法來實現(現在后臺改不了)

<form id="form" action="http://*/api/gateway" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="upload_file">
<input type="hidden" name="appKey" value="appKey">
<input type="hidden" name="pampasCall" value="pampasCall">
<input type="hidden" name="pathName" value="pathName">
<input type="hidden" name="sign" value="signs">
<input type="hidden" name="timestamp" value="timestamp">
<button type="submit">提交</button>
</form>

回答
編輯回答
過客

你要是用原生的form提交,肯定是要跳轉的
你要么自己直接用xmlhttprequest/fetch創(chuàng)建請求(把form提交事件屏蔽),要么自己寫個ajax什么的

2017年8月18日 08:53
編輯回答
夢囈
<form id="form" action="http://*/api/gateway" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="upload_file">
<input type="hidden" name="appKey" value="appKey">
<input type="hidden" name="pampasCall" value="pampasCall">
<input type="hidden" name="pathName" value="pathName">
<input type="hidden" name="sign" value="signs">
<input type="hidden" name="timestamp" value="timestamp">
<button onclick="submit()">提交</button>
</form>
function submit(){
   $('#form').submit();
  return false;
}
2018年5月8日 00:14