Добавьте функцию успеха к вашему вызову .post
, которая изменит window.location
на href
по нажатой ссылке.
$( 'a' ).bind( 'click', function( e )
{
var url;
# disable click while we make a post request
e.preventDefault();
# get the url from the href attr
url = = $( this ).attr( 'href' );
# make post request
$.post(
'/blablabla/',
{
datas: mydatas
},
function()
{
# send browser to url
window.location = url;
}
);
} );
Если вы хотите, чтобы перенаправление происходило даже в случае сбоя POST, вы можете переключиться на .ajax()
и использовать параметр complete
:
$( 'a' ).bind( 'click', function( e )
{
var url;
# disable click while we make a post request
e.preventDefault();
# get the url from the href attr
url = = $( this ).attr( 'href' );
# make post request
$.ajax( {
url: '/blablabla/',
type: 'POST',
data: {
datas: mydatas
},
complete: function()
{
# send browser to url
window.location = url;
}
);
} );