I am doing a pager and I have created a function which is invoked once the document is loaded, but for some reason, when I try to use it a second time, I get the error "is not a function", I would like to know why this happens Code is as follows:
This document loads when starting the page
$(function(){
var textoPag=$("#textoPag").val();
var tipoBusq=$("#tipoBusq").val();
pagination(1);
function ajax_start(){
$body = $("body");
$body.addClass("loading");
}
function ajax_stop(){
$body = $("body");
$body.removeClass("loading");
}
function pagination(partida){
var url = MODELO+'paginacion.php';
params={act:"paginacion",
part:partida,
palabra:textoPag
}
$.ajax({
type:'POST',
url:url,
data:params,
success:function(data){
var array = eval(data);
console.log(array[1]);
$("#contePag").append(array[1]);
//$('#agrega-registros').html(array[0]);
$('#pagination').html(array[0]);
}
});
}
});
The code that calls the pager is the following
switch ($actividad) {
case 'paginacion':
$paginaActual = $_POST['part'];
$palabra=$_POST['palabra'];
$string = SERVER."paginador";
$data = file_get_contents($string);
$json = json_decode($data,true);
if ($json["success"]==true)
{
$nroPag=$json["cont"];
$nroLotes = 2;
$nroPaginas = ceil($nroPag/$nroLotes);
$lista = '';
$tabla = '';
}
if($paginaActual > 1){
$lista = $lista.'<li><a href="javascript:pagination('.($paginaActual-1).');">Anterior</a></li>';
}
for($i=1; $i<=$nroPaginas; $i++){
if($i == $paginaActual){
$lista = $lista.'<li class="active"><a href="javascript:pagination('.$i.');">'.$i.'</a></li>';
}else{
$lista = $lista.'<li><a href="javascript:pagination('.$i.');">'.$i.'</a></li>';
}
}
if($paginaActual < $nroPaginas){
$lista = $lista.'<li><a href="javascript:pagination('.($paginaActual+1).');">Siguiente</a></li>';
}
leaving the function pagination outside the ready event and initializing it, everything works fine, but in that case I can not recover the values of the inputs
$(document).ready(pagination(1));
$(function(){
............
...........
});
function pagination(partida){
var url = MODELO+'paginacion.php';
params={act:"paginacion",
part:partida,
palabra:textoPag
}
$.ajax({
type:'POST',
url:url,
data:params,
success:function(data){
var array = eval(data);
console.log(array[1]);
$("#contePag").append(array[1]);
//$('#agrega-registros').html(array[0]);
$('#pagination').html(array[0]);
}
});
}
I don't understand why I can not continue using the pagination function in the first case