What is the way Ajax is requested? 4 ways to request Ajax frequently

Source: Internet
Author: User
Tags http post

This article mainly introduces 4 kinds of commonly used request methods about Ajax, let's take a look at the four kinds of them together now.

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 are shown below. If you specify the DataType option, make sure that the server returns the correct MIME information (such as XML returns "Text/xml"). Example: saving data to the server, displaying information on success.
$.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 the information through a remote HTTP GET request. This is a simple GET request feature to replace complex $.ajax. The callback function can be called when the request succeeds. If you need to execute the function on error, use $.ajax. Instance:
$.get ("test.cgi", {name: "John", Time: "2pm"},  function (data) {    alert ("Data Loaded:" + data);});
3. Load the information through a remote HTTP POST request. (Want to see more on the topic.alibabacloud.com column to learn) This is a simple POST request function to replace the complex $.ajax. The callback function can be called when the request succeeds. If you need to execute the function on error, use $.ajax. Instance:
$.post ("/resources/addfriend.ashx", {"FID": FIDS, "fname": Fnames, "Tuid": Tuids, "Tuname": Tunames}, function (data) { C2/>if (data = = "OK") {        alert ("added successfully! ");    }})
4. Load the 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) {    $ ("

This is the end of this article (want to see more on the Topic.alibabacloud.comAJAX User manual section of the study), there are questions can be in the message below the question.

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.