AJAX

Asynchronous JavaScript and XML

Instead of always downloading entire web pages, wouldn't it be nice if you only had to download the bit that changed.

Examples:

The new AJAX style is achieved using the JavaScript function - XMLHttpRequest() and DOM, the Document Object Model. There is a JavaScript and DOM tutorial here and w3schools has guides for JavaScript, DOM and XML.

XMLHttpRequest() is available in all new browsers. I.E. requires the correct activex control to be available. Other browsers just work. This function sends a normal http request to a web server. The server replies with a snippet of code often in HTML or XML format. This is used to update one part of the loaded web page without having to reload the entire page.

 

Try this link ... [foo]

 

Your web server needs to be running PHP and, for this example, this php code needs to be present in a file named "rpc.php".
RPC stands for Remote Procedure Call because the procedure runs on a remote server.
Use "View - Document Source" to see the JavaScript code used in this page.

<?php
  // ========================================================
  // ==== This is rpc.php                                ====
  // ==== This code receives a request and sends a reply ====
  // ==== This provices the AJAX style processing        ====
  // ========================================================
  $action = $_REQUEST['action'];
  
  if ($action == 'foo')
  {
    echo "foo|<p>The AJAX style server says ... Hello World!</p>";
  }
?>

Once you have got this working, you can get your rpc code to interact with databases.