The problem that the page does not jump after WeChat payment

What I record here is only the problems I encountered, because I stepped on the same pit again and again, and I began to doubt my life.

First describe the problem: the page calls WeChat payment, and the page does not jump after the payment is successful (Android does not jump, Apple is no problem), but the progress bar at the top of the page is displayed, and the page title has changed.

Reason: Look at the following code first. Normally, the WeChat onBridgeReady method is called after the order is placed successfully. Everything is normal. However, due to a problem with my code logic, onBridgeReady is called again. The second is that the Pay Now button is bound to two click events, causing the onBridgeReady method to be called twice when the button is clicked once. When troubleshooting, you can check whether the front-end page pops up the payment window twice (turn off the active pop-up again), or check whether the back-end api has been requested twice

The above is just a record of the problems encountered by myself, for reference only.

				function onBridgeReady() {
					WeixinJSBridge.invoke('getBrandWCPayRequest', data.payParams,
						function(res) {
							// Judging that the front end returns, the WeChat team solemnly reminds: res.err_msg will return ok after the user's payment is successful, but it does not guarantee that it is absolutely reliable.
							if(res.err_msg == "get_brand_wcpay_request:ok") {
								_replace('./success.html?caseId=' + caseId + '&doctorId=' + doctorId)
							} else { //Payment failed

							}
						});
				}
				if(typeof WeixinJSBridge == "undefined") {             
					if(document.addEventListener) {                 
						document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);             
					} else if(document.attachEvent) {                 
						document.attachEvent('WeixinJSBridgeReady', onBridgeReady);                 
						document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);             
					}         
				} else {             
					onBridgeReady();         

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324690295&siteId=291194637