title: AJAX/Jquery - Get response from php file
body: <p>Hi I have a php file that when called by my ajax/jquery code inserts a row into a mySQL table. However I want some sort of feedback to know whether the insertion was successfull or not. Here is my current code:</p>
  
  <p>ajax/jquery:</p>
  
  <pre><code>$.ajax({
      url: "update.php",
      success: function(){
          alert("success");    
      },
      error:function(){
          alert("failure");
      }
  });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>$conn = "";
  try {
      $conn = new PDO( "mysql:host=XXX;dbname=XXX", "XXX", "XXX");
      $conn-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  } catch ( PDOException $e ) {
      echo "Cannot connect to database, try again later";
  }
  $stmt = $conn-&gt;prepare("INSERT INTO data (price) VALUES (:price)");
  $stmt-&gt;bindParam(":price", $price);
  $stmt-&gt;execute();
  $conn=null;
  </code></pre>