I am trying to do my pagination using ajax and trying to fetch the page number only from the href pagination link. I have other params in href as well.
<a href="?page=2&order_by=asc">2</a>
I need only 2 so that i can send it to ajax request.
I am trying to do my pagination using ajax and trying to fetch the page number only from the href pagination link. I have other params in href as well.
<a href="?page=2&order_by=asc">2</a>
I need only 2 so that i can send it to ajax request.
you may try below
function getURLParameter(url, name) {
return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1];
}
$('a').on('click',function(){
var url = $(this).attr('href');
var page_no = getURLParameter(url, 'page');
console.log(page_no);
});
Hope , it will help you
You can use replace
to get the page number:
$('a').on('click', function() {
var number = $(this).attr('href')
number = number.replace(/\D/g, '');
console.log(number);
return false;
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="?page=2&order_by=asc">2</a>