title: PHP AJAX Postback with JQUERY
body: <p>me again, i'm really getting into php now i just need to know a few things first. First of all i'm trying to do a postback to a the server without reloading the client page.  Here's an example of what i want to do: I have to textboxe, now when the user enters a number into both textboxes and clicks the add button, the total value should be calculated and displayed in the third textbox without reloading the page, i've read a bit on ajax but i'm having trouble implementing it.</p>
  
  <pre><code>&lt;?php
      if (isset($_POST["add"]))
      {
          $val1 = $_POST["val1"];
          $val2 = $_POST["val2"];
  
          $result = $val1 + $val2;
      }
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;script src="jquery-1.9.1.min.js" &gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
              if ($("#btn").click)
              {
                  var request = $.ajax({
                  url: "postback.php",
                  type: "POST",
                  data: {
                      val1 : "what goes here?",
                      val2 : "what goes here?"
  
                  }
  
                  });
                  request.done(function(msg) {
                      $("#log").html( msg );
                  });
                  request.fail(function(jqXHR, textStatus) {
                  alert( "Request failed: " + textStatus );
                  });
              }
          });
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;input type="input" name="val1"&gt;
          &lt;input type="input" name="val2"&gt;
          &lt;input type="input" name="result" value="&lt;?php echo $result ?&gt;"&gt;
          &lt;input type="submit" id="btn" name="add"&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>