I'm sending some 'for each checkbox checked' requests to a PHP file using jQuery.
How can I delay the requests in jQuery, like every second one request, to the PHP file?
The script sends all requests at same time.
var checked = []
$("input[name='checkbox[]']:checked").each(function (){
checked.push(parseInt($(this).val()));
//console.log($(this).val());
var id = $(this).val();
if (!!window.EventSource) {
var source = new EventSource("request.php?id="+id+"");
source.addEventListener('message', function(e) {
var data = JSON.parse(e.data);
var entry = data.entry;
$("#status_"+id+"").html(entry);
this.close();
return;
}, false);
}
});