I have a lil problem with opening new tab in the browser after server response. Here is a server code (I use Rails 3.0.5):
respond_to do |format|
format.js { render :json => {:url => link.url}, :status => :accepted }
end
So since I use jQuery as a default JS library after AJAX call I handle server response with this script:
$('.link').bind('ajax:success',
function(e, data, textStatus, jqXHR){
$('#megalink').attr("href", data.url);
$('#megalink').trigger('click');
});
where "megalink" is:
<a href="" style="color:white;" target="_blank" id="megalink">.</a>
So the problem is: After 202 server response n开发者_Python百科ew tab isn`t created. May be you know how to open url in the new tab?
Use window.open(data.url);
Hope that helps.
Hm, the _blank target should work, if you could setup a jsfiddle to show how it breaks, it'd be easier to help. Otherwise, you can just try doing:
window.open(thenewurl);
The browser popup blocker blocks opening a new window during script execution context.
Use jquery AJAX in a synchronous mode it will solve your problem.
精彩评论