后端返回的form表单如下
<form name="punchout_form" method="post" action="...">
<input type="hidden" name="biz_content" value="{"out_trade_no":"123450679","total_amount":"16","subject":"苹果","body":"好吃","product_code":"FAST_INSTANT_TRADE_PAY"}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>
前端接收数据后,
axios.get('/ali/pay')
.then(function(response) {
console.log(response);
const div = document.createElement('divform');
div.innerHTML = response.data;
document.body.appendChild(div);
document.forms['punchout_form'].setAttribute('target', '_blank')
document.forms['punchout_form'].submit()
}).catch(function(error) {
// 处理错误情况
console.log(error);
}).then(function() {
// 总是会执行
});
punchout_form 是返回的form表单的name