I'm developing an application using PHP, and in one of my methods I end up using an AJAX to call a PHP file. To be more specific, I'm using an each () in a div, and within that each (), I call my AJAX. The problem is that when I use AJAX the code stays in an infinite Loping.
Follow the code below...
function CriarDetalhes(idPedido){
var page = '../../../Controllers/Produtos/addDetalhes.php';
$("#carrinho").find('.carrinho-body').each(function(){
var id = $(this).data("idcarrinho");
var valor = $(this).find(".valores").val();
var qtd = $(this).find("#qtd_" + id).val();
var obj = "idProd="+ id + "&valor=" + valor + "&qtd=" + qtd + "&idPedido=" + idPedido;
$.ajax({
type: "POST",
url: page,
data: obj,
success: function(res){
CriarDetalhes(res);
}
});
});
}
can anybody help me?
</div>
I suppose if the server is returning the same 'idPedido' value, you will recurse forever because you told it to in the success handler. What does res
equal in the success handler? The same as idPedido
?
If these two values are the same that is your problem.