jquery - Displaying php results on current page -


i have coding allows me show .txt file contents of whatever file selected drop down.

<form name="add" method="post" id="add" action="show.php">    choose file:       <select name="files" id="files" onchange="this.form.submit()">           <option value="file1">file1</option>           <option value="file2">file2</option>       </select> </form> 

with corresponding show.php (yes purpose display last 3 lines of file):

<?php     $chosenfile = $_post['files'];     $file = $chosenfile.'.txt';     $contents = escapeshellarg($file);     $line = `tail -n 3 $contents`;      echo nl2br($line);     echo "<br><br>"; ?> 

trying display results below select drop down instead of direct php code:

<script>     $('#files').on('change', function(){         $.get('show.php', function(data);             $('#result').html(data);           });         }); </script>  <div id="result"></div> 

the php works , displays text contents can't display below drop down. did miss?

remove onchanged attribute form select tag

choose file: <select name="files" id="files">   <option value="file1">file1</option>   <option value="file2">file2</option> </select> 

you must send form data show.php file correct result back

 <script>   $(function(){      $('#files').on('change', function(){          $.ajax({              url: 'show.php',              type: 'post',              data: $('form#add').serialize()          }).done(function(data) {              $('#result').html(data);          });     });   });  </script> 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -