I'm attempting to use jQuery each in my new website code. At the moment, for each div class "added" on the page, it loops through them and submits an AJAX request to my PHP script which then updates the database. The problem with this is, if the user created 100 items, 100 requests would be sent which is just not acceptable. I'd prefer to send all data in 1 go, so if there are 100 items, PHP would simply have to loop through a $_GET array.
$( ".added" ).each(function() {
var position = $(this).position();
$.ajax({
type: "GET",
url: "index.php?action=save",
data: {
id: $(this).attr("id"),
top: position.top,
left: position.left,
img: $(this).attr("image")
},
success: function (data) {
//alert(data);
}
});
});
Any solutions, or for those who can send me in the right direction, I'd be very grateful.
Kind regards.