php while loop and jquery ajax -


this simple , i'm making more difficult has be. have php page, has checkbox , button. when click button should call "collection.php" page , update index page on status. took out of code in collection.php , index page still doesn't update. doing wrong?? in advance!

index.php

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">   <head>     <meta content="text/html;charset=utf-8" http-equiv="content-type">     <meta content="utf-8" http-equiv="encoding">     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>     <script type="text/javascript" language="javascript">         $(document).ready(function() {             // click trigger image             $("#mybtn").click(function() {                 if ($('#update').is(":checked"))                     var update = 'on';                 else                     var update = 'off';                  $.ajax({                     url: 'collection.php',                     type:'post',                     datatype: 'json',                     data: 'update='+update,                     cache: false,                     async: false,                     success: function(output_string){                             //alert(json.stringify(output_string));                             $('#collection_status').html(''); // clear #wines div                             $('#collection_status').append(output_string.worked + '<br/>');                     }, // end of success function of ajax form                     error: function() {                         alert("there issue collection!");                     }                 }); // end of ajax call                 return false; // keeps page not refreshing              });         });     </script> </head> <body style="background-color:#333333;color:white;font-family:verdana;text-transform:lowercase;">     <form>         <input type="checkbox" id="update" /> update existing<br />         <button id="mybtn">collect</button>     </form> <br /> <div id="collection_status"></div> </body> </html> 

collection.php

<? // movie search variables $dir = "/video/movies/"; $movie_extensions = array('mkv','mp4','m4v','avi'); $update_movies = 0;  if(isset($_post["update"]))     $update_movies = $_post["update"];  // read contents $dir if (is_dir($dir)){     if ($dh = opendir($dir)){         while (($file = readdir($dh)) !== false){             $file_info = pathinfo($file);             $output_string['worked'] = 'found <span style="color:yellowgreen;">' . $file . '</span><br />';             echo json_encode($output_string);         }         closedir($dh);     } } 

when remove echo portion collection script receive response (below works):

$output_string['worked'] = 'testing'; echo json_encode($output_string); 

once add loop errors.

as test added loop in there - fails:

for($i=0;$i<10;$i++) {     $output_string['worked'] = 'found <span style="color:yellowgreen;">' . $file . '</span><br />';     echo json_encode($output_string); } 

maybe side thought, better discussed outside of commenting:

are aware $dir = "/video/movies/"; open directory in root? instead of subdirectory of path collection.php resides in. such (on normal webservers) hope script won't have rights open directory; not continuing further in script.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

javascript - addthis share facebook and google+ url -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -