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.