Ajax callback opens a new form prevents browsers from intercepting valid methods _ajax related

Source: Internet
Author: User

Ajax callbacks open a new form to prevent the browser from intercepting, just do it!

Problem Analysis:

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:
Open a new form can only be triggered in the Click event, click the event within the callback function to open the window experience is intercepted, the browser will think that the ads window and other code

Solution 1:

function Click_fun_new () { 
  var tempwindow=window.open ();//Open temporary form first, because it is triggered in 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";////When the callback changes the temporary form's path 
    }, 
    Error:function () { 
      tempwindow.close ()//callback discovers 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 ', 
    ' DataType ': ' json ', ' 
    data ': Data, 
    ' async ': false,//sync request 
    success:function (data) { 
      $ ("#a"). attr ("href "," www.baidu.com ")////////When the callback changes the HREF flag = true;//Change flag for a label on the page or created 
    , 
    error:function () { 
       
    } 
  }); 
  if (flag) { 
    $ ("#a"). Click ();//href property changes after analog click 
  } 
} 

The above is the Ajax callback to open a new form to prevent browser blocking the two methods, I hope to help you learn.

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.