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: Opening a new form can only be triggered within a click event, click inside the callback function within the event to open the window experience is blocked, the browser will be considered to be ads pop-up code
Resolution 1:
function Click_fun_new () { var tempwindow=window.open ();//Open the temporary form first, because it is triggered within 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";//Change the path of the temporary form when the callback }, Error:function () { tempwindow.close ();//callback found can close the previous temporary form}}) without opening the form ;}
Resolution 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 ");//change the HREF flag = true;//change flag on a page or create a label when the callback occurs }, error:function () { } }); if (flag) { $ ("#a"). Click ();//href property changes after the simulation hit }}
Ajax callback opens a new form to prevent browser interception