I have a jquery loop, which i want to call and use ajax for each element in the loop.
var splitted = [1,2,3];
var categoriesID = [4,5,6];
$.each(splitted, function(index, val)
{
$.ajax({
type: "GET",
url: 'index.php?act=ajax&op=showCategories&manufacturer='+val+'&categories='+categoriesID,
success: function(data) {
$(".manufacturer\\[" + val + "\\]").show();
$(".manufacturer\\[" + val + "\\]").html(data);
//alert('Load was performed.');
}
});
});
The problem is that i noticed that probably each element uses the same ajax connection, my results are the same – and of course for each element i should have gotten different results.
So – how i can close & re-open the ajax connection in every loop? OR is there another way to do so?
Better to use plain js to make a simle loop, and use jquery ajax to simplify ajax call to server. And for the same(bad) result that you are reciving from the server, my opinion is that you are sending or not sending the same params and then recieving same result, can you provide logic of getting the data… Ajax is asynchronous as the name says. So there is no need for open close connections, they are done in a parallel matherr. And jquery will take care of open/close. Also take a look at how to ask a question