[Jquery] the new window is blocked after the ajax request is successful. Solution: jqueryajax
Problem:
A problem occurred during the previous development project. After the ajax asynchronous request is successful, you need to open a new window to open the url, using window. open () method, but unfortunately it was intercepted by the browser. How can this problem be solved?
Analysis:
The browser intercepts new windows because this operation is not manually triggered by the user. Therefore, the browser considers this operation unsafe and intercepts it (but if it is _ self, there will be no such restriction ), even if the ajax callback function simulates the execution of user behaviors such as click or submit (trigger ('click'), the browser will think that it is not triggered by the user, so it cannot be safely executed, so it is intercepted.
Solution:
1. Change asynchronous mode to synchronous mode, that is, async: false
2. Point the new window to an object and modify the object url, for example:
$('.task').bind('click',function(){ var w = window.open(); $.ajax({ type: 'POST', url: '/surveyTask', dataType: 'json', error: function(){ w.close(); }, success: function(res){ w.location = res.url; } });});
Finally, it should be noted that the method of dynamically adding a new form window on the Internet is not suitable for ajax requests. At least the blogger tested it and was still intercepted by the browser.
Reference: the pop-up window solves the final aoyi, and the human will no longer be able to stop the pop-up window!
Open the new window address after ajax is successful
Define a variable outside the ajax function to assign values to rel. url.
Or write it to a hidden domain.
After jquery ajax is successful, it always enters error.
The json format you returned is incorrect.
Paste the res before eval.