关于前端:支付宝-post支付

问题

接口胜利后返回 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&notify_url=https%3A%2F%2Fwww.yinongpuhui.com%3A8000%2Forder%2FaliPayCallback&version=1.0&app_id=2021001129646221&sign_type=RSA2&timestamp=2020-09-16+15%3A24%3A53&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
 <input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;20200916152453160733&quot;,&quot;total_amount&quot;:&quot;80.00&quot;,&quot;subject&quot;:&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
 <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();
/*

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理