Recently when the payment was found to open the payment window was blocked by the browser, Baidu a bit to find out is because the window before the opening with Ajax to verify whether it can be paid, so the user is not actively triggered by the Open ixin window, the browser think this is not safe, so to intercept. Workaround One
Start by opening an empty new window, and then change the URL of the new window, with the specific code
var wd = window.open ();
$.ajax ({
type: "POST",
dataType: "JSON",
Url:url,
data: {Orderno:orderno},
success:function ( Data) {
if (data.status== ' success ') {
wd.location.href = ' http://www.baidu.com ';
} else{
alert (' orders cannot be paid. ')
}
},error:function (data) {
alert ("Loading please later. ");
}
});
The disadvantage of this approach is that regardless of whether Ajax is successful, will execute var wd = window.open (), this line of code, so the success and failure will open a new window, unless after the failure to close, but so the user experience is very bad, so I use the second way to achieve. Solution Two
Because Ajax is the default is asynchronous, so high performance, user experience is good, but this also leads to security issues, to let the browser think that the new window is safe, you must let the new window before all the Ajax is synchronized, the specific code is
$.ajax ({type: "POST", DataType: "JSON", Url:url, async:false,//synchronous request data: {Orderno:orderno}, success:function (data) {if (data.status== ' success ') {window.open ("Www.baidu
. com "); }else{alert (' orders cannot be paid.
'); }}, Error:function (data) {alert ("Loading please later.
"); }
});