I need to change href in anchor and then open link in new window, but this code doesn’t work. Any ideas? Obviously the url returned from the ajax call is correct.
<a href="http://www.google.com" target="_blank">alink</a>
$(document).ready(function(){
$('a').on('click', function(e){
e.preventDefault();
_this = $(this);
$.ajax({ type:"GET", url:A_URL, dataType:"json",
success: function(data){
var u = data.results[0].trackViewUrl;
_this.attr('href', u);
window.open(u, '_blank');
}
})
})
})
if you want change only url and open in new window:
but if you want get new url by ajax: