Ajax callback open a new form to prevent effective browser interception methods. ajax callback
Open a new form through ajax callback to prevent browser interception!
Problem Analysis:
Function click_fun () {window. open ("www.baidu.com"); // you can open $. ajax ({'url': '$ {pageContext. request. contextPath}/activity/savePrizes.htm ', 'type': 'post', 'ype ype': 'json', 'data': data, success: function (data) {window. open ("www.baidu.com"); // blocked}, error: function (){}});}
Analysis:
Opening a new form can only be triggered within the click event. Opening a form in the callback function in the click event will be blocked, and the browser will regard it as Code such as an ad pop-up window.
Solution 1:
Function click_fun_new () {var tempwindow = window. open (); // open the temporary form first, because it is triggered in the click event, it will not be intercepted $. ajax ({'url': '$ {pageContext. request. contextPath}/activity/savePrizes.htm ', 'type': 'post', 'ype ype': 'json', 'data': data, success: function (data) {tempwindow. location = "www.baidu.com"; // change the path of the temporary form during callback}, error: function () {tempwindow. close (); // callback found 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', 'ype ype': 'json', 'data': data, 'async': false, // synchronous request success: function (data) {$ ("# "). attr ("href", "www.baidu.com"); // when the callback is performed, modify the href flag of a tag on the page or created; // change the flag}, error: function () {}}); if (flag) {$ ("# "). click (); // simulate click after the href attribute is changed }}
The above are two methods for ajax callback to open a new form to prevent browser interception. I hope this will be helpful for your learning.