JQuery AJAX call (1) -- load and pass data, jqueryajax
I. load Method asynchronously requests data
Use the load () method to load data in the server through Ajax requests and place the returned data in the specified element. The call format is as follows:
Load (url, [data], [callback])
The url of the parameter is the address of the loading server. The data parameter can be set to the data sent during the request. The callback parameter is the callback function executed after the data request is successful.
2. Use the getJSON () method to asynchronously load JSON data
Using the getJSON () method, you can use Ajax asynchronous requests to obtain the arrays on the server and parse the obtained data. The results are displayed on the page. The call format is as follows:
JQuery. getJSON (url, [data], [callback]) or $. getJSON (url, [data], [callback])
Here, the url parameter is the server address for loading the json format file. The data parameter is the data sent during the request, and the callback parameter is the callback function executed after the data request is successful.
3. Use the getScript () method to asynchronously load and execute js files
The getScript () method is used to asynchronously request and execute JavaScript files in the server. The Calling format is as follows:
JQuery. getScript (url, [callback]) or $. getScript (url, [callback])
The parameter url is the server request address. The callback parameter is the callback function executed after the request is successful.
4. get data from the server using the GET () method
When the get () method is used, the GET method is used to request data from the server, and the request data is returned through the callback function parameters in the method. The call format is as follows:
$. Get (url, [callback])
The parameter url is the server request address. The callback parameter is the callback function executed after the request is successful.
5. Use the post () method to send data from the server in POST Mode
Compared with the get () method, the post () method is mostly used to send data to the server in POST mode. After the server receives the data, it processes the data and returns the processing result to the page, the call format is as follows:
$. Post (url, [data], [callback])
The parameter url is the server request address. The optional data is the data sent when a request is sent to the server. The optional callback parameter is the callback function executed after the request is successful.