Ajax callbacks open a new form to prevent the browser from intercepting, just do it!
Problem Analysis:
function Click_fun () {
window.open ("www.baidu.com");//can open
$.ajax ({
' url ': ' ${ Pagecontext.request.contextpath}/activity/saveprizes.htm ',
' type ': ' Post ',
' dataType ': ' json ',
' Data ': Data,
success:function (data) {
window.open ("www.baidu.com");/Blocked
},
error:function () {
}
});
Analysis:
Open a new form can only be triggered in the Click event, click the event within the callback function to open the window experience is intercepted, the browser will think that the ads window and other code
Solution 1:
function Click_fun_new () {
var tempwindow=window.open ();//Open temporary form first, because it is triggered in the Click event, will not be blocked
$.ajax ({
' url ': ' ${ Pagecontext.request.contextpath}/activity/saveprizes.htm ',
' type ': ' Post ',
' dataType ': ' json ',
' Data ': Data,
success:function (data) {
tempwindow.location = "www.baidu.com";////When the callback changes the temporary form's path
},
Error:function () {
tempwindow.close ()//callback discovers that the previous temporary form can be closed without opening the form
}
);
Solution 2:
function Click_fun_new () {
var flag = false;
$.ajax ({
' url ': ' ${pagecontext.request.contextpath}/activity/saveprizes.htm ', '
type ': ' Post ',
' DataType ': ' json ', '
data ': Data,
' async ': false,//sync request
success:function (data) {
$ ("#a"). attr ("href "," www.baidu.com ")////////When the callback changes the HREF flag = true;//Change flag for a label on the page or created
,
error:function () {
}
});
if (flag) {
$ ("#a"). Click ();//href property changes after analog click
}
}
The above is the Ajax callback to open a new form to prevent browser blocking the two methods, I hope to help you learn.