I have a list with pagination loaded with ajax post so if I use the pagination links (to go further or back) it reloads the page to send the page number via get.
I'm looking for a way to send the same variables (from ajax post) with the pagination links but I'd like to keep the url with the get (?page=x
). Is there any way to do this?
I wouldn't want to use global or session variables (not secure).
Any suggestion?
When I click search this is what triggers:
$('body').on('click', '.click, .pag_link', function() { // search button and change page
if($(this).is('.click'))
var url = '/search';
else {
if ($(this).text() == '«')
var url = '/search?page=' + (parseInt($('.active').text()) - 1);
else if ($(this).text() == '»')
var url = '/search?page=' + (parseInt($('.active').text()) + 1);
else
var url = '/search?page=' + parseInt($(this).text());
}
if ($('#res_prop').is(':checked')) {
var prop_type = $('#res_prop').val(),
checkbox = '#res_prop';
}
else if ($('#com_prop').is(':checked')) {
var prop_type = $('#com_prop').val(),
checkbox = '#com_prop';
}
else {
$('p.error').show();
die();
}
$.ajax({
method: 'POST',
url: url,
data: {
'do': getUrlParameter('do'),
'prop_type': prop_type,
'city': $('select[name="city"]').val(),
'zone': $('select[name="zone"]').val()
}
}).done(function(data) {
var new_content = $(data).find('#search');
$( "#search" ).html( new_content );
alert(url);
if ($(checkbox).length > 0)
$(checkbox).prop('checked', true);
});
return false;
});
Ajax loads a list and and at the bottom the pagination, if I click next/a number then the page reloads to send the get parameter and the page starts again from the beginning (I have to click search again).