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

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.