<script>
function click_a (href) {
$.ajax({
url: href,
beforeSend: function(xhr) {
xhr.setRequestHeader("custom", "my_custom_here");
},
success: function (data, status, xhr) {
window.location = xhr.url;
}
});
};
</script>
<p><a onclick="click_a('/exemple')" href="/exemple">My_link</a></p>
event клика и обрабатываем полученные данные. При этом останавливаем дальнейшую обработку event и возвращаем false из функции.event в inline способом:<a href="/exemple" onclick="click_a(event)">Ссылка</a>function click_a (e) {
e.preventDefault();
$.ajax({
url: this.href,
dataType: 'html',
beforeSend: function(xhr) {
xhr.setRequestHeader("custom", "my_custom_here");
},
success: function (data, status, xhr) {
console.log(data, status, xhr);
//window.location = xhr.url;
}
});
return !1;
};
А мне нужно чтобы он переходил, просто с добавлением header
window.location = xhr.url;function click_a (e) {
e.preventDefault();
var $this = this;
$.ajax({
url: $this.href,
dataType: 'html',
beforeSend: function(xhr) {
xhr.setRequestHeader("custom", "my_custom_here");
},
success: function (data, status, xhr) {
//console.log(data, status, xhr);
window.location = $this.href;
}
});
return !1;
};