jQuery ajax

If you want to dynamically load content into your page chances are your going to need to do some sort of request to a server in the background. The simplest way of doing this is to use jQuery's ajax function.

Here's an example of a GET request and a POST request:

$.ajax({
  type: "POST", // Set the HTTP type to POST
  url: "/serviceurl.aspx", // URL of the service
  data: "{data: [{"Field1": 1}] }", // Data to be posted to the service
  processData: false, // If set to true the data will be processed and turned into a query string
  success: (function (result) {
      // Result of the service call
  }),
  error: (function (jqXHR, textStatus, errorThrown) {
      alert(errorThrown);
  })
});

$.ajax({
  type: "GET", // Set the HTTP type to GET
  url: "/serviceurl.aspx", // URL of the service
  dataType: "jsonp", // Set what type of data you want back
  success: (function (result) {
      // Function that will be called on success
  })
});