HTML and CSS Reference
In-Depth Information
The second technique involves making an Ajax request to the server. The advantage of using Ajax is
that you don't need to send all the form data to the server. Instead, you can send only the pieces of data
that are required for processing at a given point of time. The result of the processing returned by an Ajax
request can be used to dynamically update the web page. Thus Ajax improves the responsiveness and
overall performance of a web application.
Note that although Ajax implies using XML as a data format, JSON is more commonly used than XML
due to its compactness. Most of the examples in this topic that require data transfers between client and
server use Ajax and JSON.
jQuery offers many ways to make Ajax requests to the server. They're listed in Table 2-7.
Table 2-7. jQuery Ajax Methods
Request Method
GET / POST / other
HTTP verbs also
Generic function that can be used to make Ajax calls to the
server. All the techniques listed below internally use $.ajax() to
perform their operations.
Fetches HTML markup or text from the server dynamically and
then sets it to the contents of a selected DOM element.
Makes generic GET requests to the server. For example, using the
$.get() method you can make a request to an MVC action
method and fetch data from the database.
Makes generic POST requests to the server. For example, using
the $.post() method you can submit a form to an MVC action
method for further processing.
Makes a GET requests to the server and fetches data in JSON
Loads remote script files dynamically so you can execute them
further in the code.
Using jQuery Ajax techniques, you can invoke the following types of ASP.NET server-side code:
• Web services ( .asmx )
• Web methods
• WCF services ( .svc )
• ASP.NET MVC controller action methods
• Web API
• Generic HTTP handlers ( .ashx )
Although jQuery Ajax techniques let you call ASMX web services, whenever possible you should avoid
using them because newer techniques are available.
n Note Technically speaking, you can make Ajax request to any server-side resource not listed here. However, in
most common cases it's best to encapsulate the code to be called from the client side in one of the mechanisms
Search WWH ::

Custom Search