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!