Explore jQuery's ajax use cases (c #) _ jquery

Source: Internet
Author: User
This article mainly discusses jQuery's ajax application scenarios. For more information, see. I. jQuery. ajax syntax Basics

JQuery. ajax ([options])

Overview: Load remote data using HTTP requests.

JQuery underlying AJAX implementation. For easy-to-use high-level implementation, see $. get, $. post, and so on. $. Ajax () returns the created XMLHttpRequest object. Using this method gives you more flexibility.

Data Type
The $. ajax () function depends on the information provided by the server to process the returned data. You can use the dataType option to specify different data processing methods. The data returned by the text and xml types is not processed. If it is specified as html, any embedded JavaScript will be executed before HTML is returned as a string. If the json type is specified, the obtained data is parsed as a JavaScript Object and the constructed object is returned as the result. Send data to the server. By default, Ajax requests use the GET method. If you want to use the POST method, you can set the type parameter value. This option also affects how the content in the data option is sent to the server.

Scenario 1:
Description: saves data to the server. Information is displayed when data is successfully saved. JQuery code:
$. Ajax ({
Type: "POST ",
Url: "some. php ",
Data: "name = John & location = Boston ",
Success: function (msg ){
Alert ("Data Saved:" + msg );
}
});

Scenario 2:
Description: adds the latest HTML webpage version. JQuery code:
$. Ajax ({
Url: "test.html ",
Cache: false,
Success: function (html ){
$ ("# Results"). append (html );
}
});

Load (url, [data], [callback])
Overview: Load remote HTML file code and insert it into the DOM.
By default, the GET method is used. The method is automatically converted to the POST mode when additional parameters are passed.

Scenario 1:
Description: loads the content of the feeds.html file. JQuery code:
$ ("# Feeds"). load ("feeds.html ");

JQuery. get (url, [data], [callback], [type]) and jQuery. post (url, [data], [callback], [type])

Overview: load information through remote http get or POST requests.
This is a simple GET or POST Request function to replace complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax.
Description: displays the return value of test. aspx (HTML or XML, depending on the returned value), and adds a set of request parameters. JQuery code:
$. Get ("test. aspx", {name: "John", time: "2 "},
Function (data ){
Alert ("Data Loaded:" + data );
});
$. Post ("test. aspx", {name: "John", time: "2 "},
Function (data ){
Alert ("Data Loaded:" + data );
});

The above is the basic syntax. We only need to understand it first. If you are familiar with it, we will start to discuss the above methods and use cases step by step.

Ii. Practical practices of jQuery. ajax with ASP. NET

First, create the Default. aspx page as the request initiation page and obtain the returned value. The page code Default. aspx is:

The Code is as follows:


<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "JqueryAjax2. _ Default" %>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.