Ajax callback open a new form to prevent effective browser interception methods. ajax callback

Source: Internet
Author: User

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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.