jquery Basics (Ajax,load (), Getjson (), GetScript (), post (), Ajax (), synchronous/asynchronous request data)

Source: Internet
Author: User
Tags getscript

1. Using the load () method to request data asynchronously

Use the load () method to load the data from the server via an AJAX request and place the returned data into the specified element, which is called in the following format: load (Url,[data],[callback])The parameter URL is the load server address, and optionally the data parameter is the callback function that is sent when the data request is requested, and the callback parameter is the execution of the database.

2Use the Getjson () method to asynchronously load JSON-formatted data using the Getjson () method, you can obtain data from the server by means of an AJAX asynchronous request, and parse the obtained data in the page, which is called in the following format: Jquery.getjson (Url,[data],[callback]) or $.getjson (Url,[data],[callback])Where the URL parameter is the server address for the request to load the JSON-formatted file, the option data parameter is the one that is sent when the request is requested, and the callback parameter is the callback function that executes after the data request succeeds.

personal writing.

2. Use the Getscript () method to asynchronously load and execute a JS file using the Getscript () method to asynchronously request and execute a JavaScript-formatted file in the server, whose invocation format is as follows: Jquery.getscript (Url,[callback]) or $.getscript (Url,[callback])The parameter URL is the server request address, and the optional callback parameter is the callback function that executes after the request succeeds.

3. Using the Get () method to get data from the server using the Get () method, the Get method is used to request data from the server, and the requested data is returned through the parameters of the callback function in the method, and its invocation format is as follows: $.get (Url,[callback])The parameter URL is the server request address, and the optional callback parameter is the callback function that executes after the request succeeds.

4. The post () method uses the post () method to send data from the server as compared to the Get () method, which is used to send data to the server by post, the server receives the data, processes it, and returns the processing result to the page, called the following format:   $.post (Url,[data],[callback])The parameter URL is the server request address, optionally the data to be sent to the server when requested, the optional callback parameter is the callback function executed after the request succeeds.

5. Use the Serialize () method to serialize form element values use the Serialize () method to serialize element values in the form that have the name attribute, and to generate a standard URL-encoded text string that can be used directly in the AJAX request, with the following invocation format: $ (selector). Serialize ()Where the selector parameter is the element in one or more forms or the form element itself.

6.Using the Ajax () method to load server data using the Ajax () method is the lowest, most powerful way to request server data, not only to get the data returned by the server, but also to send a request to the server and pass a numeric value, which is called in the following format: jquery.ajax ([Settings]) or $.ajax ([settings])Where the parameter settings is the configuration object when the AJAX request is sent, in which the URL represents the path requested by the server, data is passed at the request, datatype is the data type returned by the server, success is the callback function for the successful execution of the request, Type is the way in which data requests are sent, the default is get.

7. Use the Ajaxsetup () method to set global AJAX default options use the Ajaxsetup () method to set some of the global option values for an AJAX request, and after the setup is complete, the subsequent AJAX requests will not need to add these option values, which are called in the following format:   jquery.ajaxsetup ([options]) or $.ajaxsetup ([options])The optional options parameter is an object that sets the global option value for an AJAX request.

8. Use the Ajaxstart () and Ajaxstop () methods  The Ajaxstart () and Ajaxstop () methods are bound Ajax events. The Ajaxstart () method is used to trigger a function before the AJAX request is issued, and the Ajaxstop () method is used to trigger the function after the AJAX request is completed. They are called in the following format:   $ (selector). Ajaxstart (function ()) and $ (selector). Ajaxstop (function ())Where two of the parentheses in the method are bound functions, the function that executes the ajaxstop () method binds the Ajaxstart () method when the request is executed before the AJAX request is sent.  

jquery Basics (Ajax,load (), Getjson (), GetScript (), post (), Ajax (), synchronous/asynchronous request data)

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.