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.