Introduction to four common request methods of ajax in jQuery, jqueryajax

Source: Internet
Author: User

Introduction to four common request methods of ajax in jQuery, jqueryajax

AJAX is a technology used to exchange data with servers. It can be used to update a part of a webpage when the entire page is added.

Four common ajax request methods in jQuery:

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

$. Ajax () has only one parameter: The parameter key/value object, which contains information about various configurations and callback functions. For detailed Parameter options, see.

If you specify the dataType option, make sure that the server returns the correct MIME information (for example, xml returns "text/xml ").

Instance:

Save the data to the server. If the data is successfully saved, the information is displayed.

$.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 complex $. ajax. You can call the callback function when the request is successful. To execute 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 complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax.

Instance:

$. Post ("/Resources/addfriend. ashx ", {" fid ": fids," fname ": fnames," tuid ": tuids," tuname ": tunames}, function (data) {if (data = "OK") {alert ("added successfully! ");}})

4. Load JSON data through http get requests.

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){$("

The above section describes four common ajax request methods in jQuery. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.