javascript - How can I pause a jQuery .each() loop, while waiting for user input? -


Before I continue to get a jQuery .each loop to wait for user input There is a problem in repeatedly repeating This is my code (I have commented on what I would like to do):

  & lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "common_components.css" /> & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Link rel = "stylesheet" href = "slider.css" & gt; & Lt ;? Php include_once 'common_components.php'; $ Query = $ dbh- & gt; Queries ("SELECT movies_dir FROM settings"); $ Line = $ query- & gt; Obtain (PDO :: FETCH_ASSOC); Date_default_timezone_set ('UTC'); Echo "& lt; title & gt; movie scanner & lt; / title & gt;"; ? & Gt; & Lt; Script src = "jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Var revolve = "not done"; Function EnterManually () {Warning ("Entering Data Manually"); // data has been entered manually so that the exit function & amp; Move the next index to the loop on the loop in the document. Retval = "done"; } Function insertIntoDB (id, path) {var request = $ Ajax ({url: "update_movie.php? Id =" + id + "& path =" + path, type: "received", data type: "html"}); Request.done (data (if data == 0) {Warning ("Movie successfully inserted"); // data has been entered successfully (please update Movie Return 0). The next index on the loop in the search_file function & document; Retval = "done";} and if (data == 1) {warnings ("Unable to insert movie!"); //update_movie.php returns error (1 return), so exit this function but exit the search_file function Do not do - wait to click on the second set of user details. Retval = "not done";}}); } Var file = & lt ;? Php echo json_encode (preg_grep ('/^([^.])/', scanderer (genuine path ($ line ["movies_rd"]))))? & Gt ;; Function search_file (path) {var xmlhttp; Xmlhttp = New XMLHttpRequest (); Xmlhttp.open ("GET", "? Search_file.php path =" + path, false); // load file_file.php with xmlhttp.send (); // $ Send off the file ('#come'). Blank (); // Clear design of the content document. GetElementById ("Results"). InnerHTML = xmlhttp.responseText; // in the load output page} & lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "result" & gt; & Lt; Script & gt; $ (Document) .ready (function () {$ .each (files, functions (key, value) {search_file ("& lt ;? php adds echo (actual path ($ line [" movies_dir "]))? Gt; "+" \\ "+ value); // Repeat the next item in the array and run the search_file function});}); & Lt; / Script & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Basically, the 'file' variable contains a JSON array of file paths. For each index in the array, the Search_file function is run on that path, which should display the list of search results for that file - Calling & amp; Displaying search_file.php page.

When the user clicks on any of the results from the list displayed, then he should try to insert ( InsertIntoDB function, which is update_movie.php file) has a record in the database

if that is successful in joining ( update_movie 0 returns) (or the EnterManually function is triggered ) Then the function should exit all, and

if the inserting process is not successful (hence update_movie 1 will come back).

, then nothing should be done - .each should not increase in the loop. Instead, we should wait for the user to click on another result.

At the moment, I can not wait for the .each loop until the user has clicked on the result, it only grows up to the last item in the loop .

You can just go through the files at a time.

  var index = 0; $ ("# Results") ("Click", function () {search_file ("& lt ;? php adds buzz (actual path ($ line [" movies_dir "]))? & Gt;" + "\ +" + files [index]) ; Index ++;});  

This idea every time you click on the result's div, it will load the next file. I did not include the code to check the boundary, and things like.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -