接口成功後返回 form 等一堆碼
但不跳轉
<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?app_cert_sn=78b35e11ea21431114619365ac443f29&charset=UTF-8&alipay_root_cert_sn=687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6&method=alipay.trade.page.pay&sign=UGxkPWF5w0hhMI0cUu%2BZPJZE3LCs%%2B81WCeM1P6mOqeXwToIqeL4NP1Gm6%2FzP%%2Fq3gtve%2BLJhvUpdgtZHOlvPPnohecyRiD5touIdee7%2BRgk6N35Zb53J3RTMLuWEml%3D%3D&return_url=http%3A%2F%2Fwww.yinongpuhui.com¬ify_url=https%3A%2F%2Fwww.yinongpuhui.com%3A8000%2Forder%2FaliPayCallback&version=1.0&app_id=2021001129646221&sign_type=RSA2×tamp=2020-09-16+15%3A24%3A53&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json"> <input type="hidden" name="biz_content" value="{"out_trade_no":"20200916152453160733","total_amount":"80.00","subject":"product_code":"FAST_INSTANT_TRADE_PAY"}"> <input type="submit" value="當即支付" > </form>
頁面中加一個divform標籤 (如下代碼放在接口成功的位置)java
//支付寶支付 // 添加以前先刪除一下,若是單頁面,頁面不刷新,添加進去的內容會一直保留在頁面中,二次調用form表單會出錯 let divForm = document.getElementsByTagName('divform') if (divForm.length) { console.log('divForm.length') /*document.body.removeChild(divForm[0])*/ document.getElementsByTagName.innerHTML = ""; // 不清除會出錯 } const div=document.createElement('divform'); div.innerHTML=response; // data就是接口返回的form 表單字符串 document.body.appendChild(div); document.forms[0].setAttribute('target', '_blank') // 新開窗口跳轉 document.forms[0].submit(); /*