[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Ajax Pagination

Hiago Vitor

5/25/2015 7:35:00 PM

I made this code of pagination but i have one problem tha is when i change the page links stop working (first time always work, but when the button event fires the "new" buttons stop work in the "new page")

Does anyone know why that happens ?

$(document).ready(function(){
var json_data = "";

jQuery.ajax({
url: "view/pesquisa-produto.view.php",
dataType: "json",
//async: false,
success: function( result) {
if(result[0].fail == "nada"){
json_data =
'<div align="center">'+
//Mensagem com que nao foi encontrado
'<tr>'+
'<td lign="center">'+'<h3 padding="30px">Lamentamos, nenhum produto encontrado com esse critério de pesquisa: '+result[0].pesquisa+'<h3>'+'</td>'+
'</tr>'+
//Mesagem de pesquisar novamente
'<tr>'+
'<td>'+'<h3 padding="30px">'+"Tente novamente com outro termo para busca..."+'<h3>'+'</td>'+
'</tr>'+
'</div>';
$('#conteudoPesquisado').html(json_data);
}
else if(result != ""){
var tamanho = result.length;
var pagina = 1;
var quantidade = 16;
var totalPaginas = (Math.ceil(tamanho/quantidade) );

if(tamanho < (quantidade + 1) ){
json_data += '<table>';
$.each(result,function(index) {
if (index % 4 === 0) {
json_data += '<tr>';
}

json_data += '<td><div class="pesquisaProduto">'
+ '<span>'+'<img style="width:100px;heigth:100px;" src="'+result[index].foto+'"</span>'
+ '<span>'+"<br>"+"<a href='compras.php?Produto= "+result[index].id+" ' >"+result[index].nome+'</a>'+'</span>'
+ '<span>'+"<br>R$"+result[index].preco+'</span>'
+'</div></td>';

if ( ( (index+1) % 4) === 0) {
json_data += '</tr>';
}
});
json_data += '</table>';
}
else{
var c = 0;

json_data += '<table>';

for(var c = (quantidade * (pagina - 1) ) ; c < (quantidade * pagina); c++){
if(result[c] == undefined){
json_data += '</tr>';
json_data += '</table>';

json_data += '<div class="pesquisaProdutoPg" >';
for(var i = 1; i < (totalPaginas+1); i++){
json_data +=
'<input name="paginas" float="left" id="pagina '+i+'" type="button" value="'+i+'" class="botao-adic-show" style=" -webkit-appearance: button;cursor: pointer;border: #191919 solid 2px;background: #FFFFFF;color: black;width: 30px;font-size: 25px;">';
}
json_data += '</div>';

$('#conteudoPesquisado').html(json_data);
die();
}

if (c % 4 === 0) {
json_data += '<tr>';
}

json_data += '<td><div class="pesquisaProduto">'
+ '<span>'+'<img style="width:100px;heigth:100px;" src="'+result[c].foto+'"</span>'
+ '<span>'+"<br>"+"<a href='compras.php?Produto= "+result[c].id+" ' >"+result[c].nome+'</a>'+'</span>'
+ '<span>'+"<br>R$"+result[c].preco+'</span>'
+'</div></td>';

if ( ( (c+1) % 4) === 0) {
json_data += '</tr>';
}
}
json_data += '</table>';

json_data += '<div class="pesquisaProdutoPg" >';
for(var i = 1; i < (totalPaginas+1); i++){
json_data +=
'<input name="pagina" float="left" id="pagina '+i+'" type="button" value="'+i+'" class="botao-adic-show" style=" -webkit-appearance: button;cursor: pointer;border: #191919 solid 2px;background: #FFFFFF;color: black;width: 30px;font-size: 25px;">';
}
json_data += '</div>';
}

$('#conteudoPesquisado').html(json_data);

$("input[name=pagina]").click(function(){
json_data = "";
var pagina = this.id;
pagina = pagina.substr(-1);

json_data += '<table>';
for(var c = (quantidade * (pagina - 1) ) ; c<(quantidade * pagina); c++){
if(result[c] == undefined){
json_data += '</tr>';
json_data += '</table>';

json_data += '<div class="pesquisaProdutoPg" >';
for(var i = 1; i < (totalPaginas+1); i++){
json_data +=
'<input name="paginas" float="left" id="pagina '+i+'" type="button" value="'+i+'" class="botao-adic-show" style=" -webkit-appearance: button;cursor: pointer;border: #191919 solid 2px;background: #FFFFFF;color: black;width: 30px;font-size: 25px;">';
}
json_data += '</div>';

$('#conteudoPesquisado').html(json_data);
die();
}

if (c % 4 === 0) {
json_data += '<tr>';
}

json_data += '<td><div class="pesquisaProduto">'
+ '<span>'+'<img style="width:100px;heigth:100px;" src="'+result[c].foto+'"</span>'
+ '<span>'+"<br>"+"<a href='compras.php?Produto= "+result[c].id+" ' >"+result[c].nome+'</a>'+'</span>'
+ '<span>'+"<br>R$"+result[c].preco+'</span>'
+'</div></td>';
if ( ( (c+1) % 4) === 0) {
json_data += '</tr>';
}
}
json_data += '</table>';

json_data += '<div class="pesquisaProdutoPg" >';
for(var i = 1; i < (totalPaginas+1); i++){
json_data +=
'<input name="pagina" float="left" id="pagina '+i+'" type="button" value="'+i+'" class="botao-adic-show" style=" -webkit-appearance: button;cursor: pointer;border: #191919 solid 2px;background: #FFFFFF;color: black;width: 30px;font-size: 25px;">';
}
json_data += '</div>';

$('#conteudoPesquisado').html(json_data);
});
}
},

error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.n Verify Network.');
} else
if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else
if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else
if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else
if (exception === 'timeout') {
alert('Time out error.');
} else
if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.n' + jqXHR.responseText);
}
}
});
});
2 Answers

Patriot Games

3/29/2010 10:17:00 PM

0

On 29 Mar 2010 13:48:40 GMT, Bert Hyman <bert@iphouse.com> wrote:
>In news:5a0ba1b4-3958-4f63-850c-e69b39bec946@e6g2000yqh.googlegroups.com
>"Tom Sr." <tomswiftsenior@gmail.com> wrote:
>> We've been over this, repeatedly, Bobby. It is NOT any form of abuse
>> or violation of Google Groups' Terms of Service.
>Ordinarily, I'd simply suggest that you apply the killfile or filter
>mechanism of your news client, but since you're a googlegrouper, I guess
>you're just stuck.

There is allegedly a browser plug-in that somehow filters Google
Groups...

Nappy Tom is about 10,000 times not smart enough to install a Browser
Plug-In so, yeah, he's stuck...

Patriot Games

3/29/2010 10:29:00 PM

0

On Mon, 29 Mar 2010 06:28:09 -0700 (PDT), Anonymous Infidel - the
anti-political talking head <messiah2999@yahoo.com> wrote:
><snip bs nobody is going to read>
>Everybody knows the liars on this group are you faggy libs. [Now go
>die from your AIDs, homo]

Bwahahahahahhaa!!!