Chapter 25A. Using jQuery for Ajax in Web Forms

In Lesson 23 you learned about using JavaScript to perform client-side programming. In that lesson you were introduced to the jQuery script library. In Lesson 24A you learned how to use the AJAX Extensions provided by the ASP.NET Web Forms framework. In this lesson I teach you how to use the Ajax tools provided by jQuery.

AJAX METHODS

These are the Ajax methods that jQuery provides:

  • $.ajax — This method performs an Ajax request. All of the other methods in this list are shortcuts that use this method.

  • $.get — This method loads HTML using an HTTP GET request.

  • $.getJSON — This method loads JSON-encoded data using an HTTP GET request.

  • $.getScript — This method loads a JavaScript file using an HTTP GET request and executes it.

  • .load — This method loads HTML into the specified element.

  • $.post — This method loads HTML using an HTTP POST request.

    Note

    JSON stands for JavaScript Object Notation. It is a format used to represent simple data structures and objects in a lightweight, text-based, human-readable format.

The simplest way to fetch data asynchronously from the server is to use the .load method. The .load method can be used to replace the UpdatePanel server control that was introduced in Lesson 24A. These are the parameters of the .load method:

  • url — This is a string that contains the URL to which the request is sent. This is the only required parameter.

  • data — This is a string that contains any data that needs to be sent to the URL.

  • complete — This ...

Get ASP.NET 4 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.