How to open a new window address after a successful request by Ajax
This article mainly introduces Ajax how to achieve a successful request to open a new window address, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
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 ");})
After the url request is successful, window.open (rel.url, "_ blank"); will be blocked by the browser and cannot open a new window. If you put window.open () outside the ajax, the problem will be solved 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");}
Let's take a look at opening a new window after the Ajax response
There is a function in the recent development, after clicking a link, to determine whether the current user is logged in, if not, need to pop up a login dialog box, after the user logs in, and then open the link to the Url in a new window (tab).
Don't say much, just post the code:
$(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 synchronization to prevent pop-up pages from being intercepted by browsers async: false, success: function (oData) {ssoAction ();});} return false;})
Important: you need to use synchronous submission, use asynchronous submission, and open a new window (tag) in callback, which will be considered malicious by the browser.
Thank you for reading this article carefully. I hope the article "Ajax how to open a new window address after a successful request" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!