title: ajax display query result in text box
body: <p>OK, so I've installed jQuery on my GoDaddy hosting account. I need to display a result in a text box and have done my HTML, which gets a user input, a button click and a results area (div id=status). I want to simply put the result in a box without having to refresh the page. I'm trying this json thing and AJAX to accomplish this and I'm trying to figure out what is wrong with my attempt. Here is the HTML.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1  /DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;script language='JavaScript' type='text/javascript'&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Test&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;Miles &lt;input name="miles" id="miles" type="text" /&gt; &lt;button type="button" name="getdata" id="getdata"&gt;Submit&lt;/button&gt;&lt;/p&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;div id="status"&gt;
  
  &lt;/div&gt;
  &lt;script type="text/javascript" language="javascript"&gt;
  $('getdata').click(function(){
  
     $.ajax({
             url: 'process.php',
             type:'POST',
             dataType: 'json',
             success: function(output_string){
                     $('#result_table').append(output_string);
                 }
             ));
  
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and it should be sent to process.php file:</p>
  
  <pre><code>&lt;?php
  $hostname = 'myhost.com';
  $username = 'ratetable';
  $password = 'mypassword';
  
  $miles = (int) $_POST['miles'];
  
  try 
  {
     $db = new PDO("mysql:host=$hostname;dbname=ratetable", $username, $password);
  
     foreach($db-&gt;query('SELECT * FROM rates WHERE mileage&lt;= ' . $miles . ' ORDER BY mileage DESC LIMIT 1') as $row) {
     $output_string .= '&lt;input type='text' name='answer' value='" . $row['ratepermile'] . "'&gt;';
  
     }
  }         
  echo json_encode($output_string);
  catch (PDOException $e) {
     echo $e-&gt;getMessage();
     throw($e);
  }
  ?&gt;
  </code></pre>
  
  <p>I tried to use an example to construct this and nothing happens...not even the HTML form. What is wrong with this?  </p>
  
  <p>Thanks for having a look. </p>