Open the new window address after the Ajax request is successful.

Source: Internet
Author: User

Open the new window address after the Ajax request is successful.

The key code is as follows:

jQuery.ajax({"type":"post","url":"http://www.baidu.com", "success":function(rel){if(rel.isSuccess){ window.open(rel.url,"_blank");}}}); 

Window. open (rel. url, "_ blank"); will be blocked by the browser, cannot open a new window, if the window. open () is placed outside ajax, and the problem is solved. The Code is as follows:

var result="";jQuery.ajax({"type":"post","url":"http://www.baidu.com", "success":function(rel){if(rel.isSuccess){ result=rel.url;//window.open(rel.url,"_blank");}}});if(result.length>0){window.open(result,"_blank");}

Next let's take a look at opening a new window after the Ajax response.

A function is available in recent development. After clicking a link, you need to determine whether the current user is logged on. If you have not logged on, a logon dialog box is displayed, in the new window (TAG), open the Url to which the link points.

Not to mention, paste the Code directly:

$ (Document ). delegate ("a", "click", function () {var actionUrl = $ (this ). attr ("href"); var ssoAction = function () {window. open (actionUrl, '_ blank') ;}; if (isLogin () {ssoAction () ;}else {popup. show ({login: function () {$. ajax ({type: "post", dataType: "json", url: "/Account/Login", data: $ ("frmLogin "). serialize (), // change the sending method to synchronous to avoid being intercepted by the browser. async: false, success: function (oData) {ssoAction ();}});});} return false ;});

Important: Synchronous submission and asynchronous submission are required. opening a new window (TAG) in callback will be considered malicious by the browser.

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.