4 of the most common requests for Ajax in jquery are _ajax related

Source: Internet
Author: User
Tags http post

AJAX is a technique for exchanging data with the server, and it can be used to update part of the page in the context of the entire page.

4 Common ways to request Ajax in jquery:

1.$.ajax () returns the XMLHttpRequest object that it created.

$.ajax () has only one parameter: The parameter Key/value object, which contains the configuration and callback function information. Detailed parameter options see below.

If you specify the DataType option, make sure that the server returns the correct MIME information (such as the XML return "Text/xml").

Instance:

Saves data to the server and displays information when it succeeds.

$.ajax ({
type: "Post",
dataType: "html",
URL: '/resources/getlist.ashx ',
Data:dataurl,
Success:function (data) {
if (data!= "") {
$ ("#pager"). Pager ({pagenumber:pagenumber, Pagecount:data.split (" $$ ") [1], buttonclickcallback:pageclick});
$ ("#anhtml"). HTML (Data.split ("$$") [0];}
}
);

2. Load information through a remote HTTP GET request.

This is a simple GET request function to replace the complex $.ajax. Callback functions can be invoked when the request succeeds. If you need to perform a function when an error occurs, use $.ajax.

Instance:

$.get ("test.cgi", {name: "John", Time: "2pm"},
function (data) {
alert ("Data Loaded:" + data);
});

3. Load information through a remote HTTP POST request.

This is a simple POST request function to replace the complex $.ajax. Callback functions can be invoked when the request succeeds. If you need to perform a function when an error occurs, use $.ajax.

Instance:

$.post ("/resources/addfriend.ashx", {"FID": FIDS, "fname": Fnames, "Tuid": Tuids, "Tuname": Tunames}, function (data) { C6/>if (data = = "OK") {
alert ("Add success!") ");
}
})

4. Load JSON data through an HTTP GET request.

Instance:

$.getjson ("Http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json &jsoncallback=? ",
function (data) {
$.each (data.items, function (I,item) {
$ ("  "). attr ("src", item.media.m). Appendto ("#images");
if (i = = 3) return false;});

The above is a small set of jquery to introduce the Ajax 4 kinds of commonly used in the introduction of the request, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.