To consolidate a few SQL calls I’m trying to make one query to the server and then have the client side iterate through each result. The caveat is that I need to wait for user input before processing the next result. Is this possible?
I have a jquery call similar to below:
$.post('functions/file_functions.php', {type: 'test', f: 'load'}, function(data) {
if (data.success) {
$.each(data.files, function() {
// Can I wait for user input at this point and then process the next
// file after a users interaction (e.g. a button click)?
});
}
}, "json");
I’m going to expand on my comment a bit, and hopefully make it a useful answer. JavaScript is single-threaded, so there’s no way to block the execution of a function while waiting for something else (such as an element being clicked on) to happen. Instead, what you could do is store the list of files into an array when the AJAX POST request returns successfully, then use a separate
clickevent handler to cycle through them (I assume getting one file per click).Code may look something like this: