JQuery. get ()
JQuery. ajax (): executes asynchronous HTTP (Ajax) requests.
$ (Selector). get (url, data, success (response, status, xhr), dataType)
The simple GET request function replaces the complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax.
Example:
$. Get ("product? Type = 111 ", {id: '000000', name: 'qingteng Garden ',}, function (data, state) {// The returned data alert (data) is displayed here; // The returned status alert (state );})
$.ajax({ url: url, data: data, success: success, dataType: dataType});
The post () method loads data from the server through an http post request
This method is similar to $. get (), but only one type parameter is added. Here we will only introduce the type parameter. For more information, see $. get () above.
Type: type indicates the request data type, which can be html, xml, json, and Other types. If we set this parameter to json, the returned format is json, and $. the format returned by get () is the same as that returned by get.
JQuery. post (url, data, success (data, textStatus, jqXHR), dataType)
$.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType});
$. Post ("product? Type = 111 ", {id: '000000', name: 'qingteng Garden ',}, function (data, state) {// The returned data alert (data) is displayed here; // The returned status alert (state) ;}, "json ")
JQuery. getJSON (url, data, success (data, status, xhr ))
$.ajax({ url: url, data: data, success: callback, dataType: json});
$.getJSON("test.js", function(json){ alert("JSON Data: " + json.users[3].name);});
All options can be set globally using the $. ajaxSetup () function.
JQuery. ajax ([settings])
// JQuery code: $ (document ). ready (function () {$ ("# b01 "). click (function () {htmlobj = $. ajax ({url: "/jquery/test1.txt", async: false}); $ ("# myDiv" ).html (htmlobj. responseText );});});
// HTML code: <div id = "myDiv">
-The key/value data sent to the server from the specified resource request data will be appended to the request URL as QueryString. The format of the data returned by the server is actually a string, it is not the json data format we want
- -Submit the data to be processed to the specified resource. the get () parameter is similar. A type parameter is added, and the type is the returned data type, which can be html, xml, json, and Other types. If we set this parameter to json, the returned format is in json format. If no value is set, it is equal to $. get () returns the same format as a string.