Prerequisites: You need to import the relevant js file jquery. js
$. Post (url, data, success (data, textStatus, jqXHR), dataType)
Url: required. Specifies the URL to which the request is sent.
Data: Optional. Ing or string value. Specifies the data sent to the server together with the request.
Success (data, textStatus, jqXHR): Optional. The callback function executed when the request is successful.
DataType: Smart judgment (xml, json, script, or html) is performed by default ).
$. GetJSON (url, data, success (data, textStatus, xhr ))
Url: required. Specifies the URL of the request.
Data: Optional. Specifies the data sent to the server together with the request.
Success (data, status, xhr ):
Optional. Specifies the function that runs when the request is successful.
Additional parameters:
Response-contains the result data from the request
Status-contains the Request status
Xhr-contains XMLHttpRequest object
Extended write:
Copy codeThe Code is as follows:
$. Ajax ({
Type: 'post' or 'get ',
Url: url,
Data: data,
Success: callback,
DataType: json
});
DataType has these types: xml, json, script, or html
Note:
Use $. when using the getJson method, if a Chinese character is input into the url, it must be escaped first (without escaping, $ _ GET ['V'] Under ie8 will not GET the value, and other browsers will not have this problem)
Eg:
Var url = "/api. php? Op = product & v = "+ encodeURIComponent ('good learn ');