This works like a charm:
// Direct window.open()
$('#btnDirect').on('click',function(){
window.open('http://google.com')
})
var success = false; //NOTE THIS
// AJAX window.open()
$('#btnAJAX').on("click", function(){
$.ajax({
url: "/user/login/",
context: document.body,
async:false, //NOTE THIS
success: function(){ //THIS ALSO CHANGED
success = true
}
});
if(success){ //AND THIS CHANGED
window.open('http://google.com')
}
})
What this does is when the Ajax call is success it sets the variable success to true.
The async:false
propperty makes sure that the if statement is fired after the Ajax call is completed.
So the window.open is fired in the same circumstances as your direct link.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…