With jQuery Ajax updating parts of a webpage becomes quite easy - there's no need any longer to reload the whole webpage.

My Shoppingcart:
Empty

This makes Ajax of great use for shoppingcarts or other functionality that only requires parts of a website to be updated. Take a look at and try the example above.

Since Ajax is a clientside script it is implemented by using the script tag. In this example, clicking on 'Add to shoppingcart' calls the function add() to which the specific item number is given as a parameter. Subsequently an Ajax POST request is made, containing the specific item number as the submitted data, to an URL that handles the database update. The script to add items looks like this:


function add(item_number){
  $.ajax({
    type: "POST",
    url: "/add_to_cart",
    data: { product: item_number }
  });
}

Enjoy your Ajax calls!