Ajax callback opens a new form to prevent browser interception

Source: Internet
Author: User

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

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.