问题
接口成功后返回 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标签 (以下代码放在接口成功的位置)
//支付宝支付
// 添加之前先删除一下,如果单页面,页面不刷新,添加进去的内容会一直保留在页面中,二次调用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();
/*
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。