Loading stuff through Ajax-requests is simple with jQuery. The following code loads a remote page using an asnychronous XML HTTP request and replaces the content of the HTML tag with the ID “panel”:

 jQuery("#panel").load("/items/"+id);

If you want to add more options, you can use the following notation:

 jQuery.ajax({
         type: "GET",
         url: '/items/'+id,
         data: "category=excellent",
         async: true,
         dataType: "script",
         success: function(html){
            jQuery("#panel").html(html);
         }
  });

Posting data is also simple, just exchange the type “GET” by “POST”. For more examples see the documentation.

Advertisements