Read & lt; jquery authoritative guide & gt; [4]-Ajax

Source: Internet
Author: User
Tags getscript

① Load ()

$. Load (url, data, callback)

  • The url of the page to be loaded,
  • Data key/value format sent to the server,
  • Callback indicates the callback function that is returned to the page after loading successfully.

The url can also filter page elements.

<script type="text/javascript">"#Button1").click( () {                 $( "#divTip").load("a.html .aa" ); </script>

A.html code:

<div class="clsShow">test</div><div class="clsShow aa">test1</div>

Html:

                                                
<Script type = "text/javascript"> "# Button1 "). click ("news. js ", html =" "+ = (index + 1 + =" title: "+ item. title + "<br/>" + = "Date:" + item. date + "<br/>" "# divTip" </script>

③ GetScript ()

$. GetScript (url, callback): Get the js file and automatically execute the injection script.

Parameter: url is the js file address to be loaded, and callback is the callback function.

Instance:

News1.js:

Data = "title": "The New tianlong Babu is about to stop broadcasting" "date": "2014-1-26" "title": "Who do you like as a singer" "date ": "2014-1-24" html = "" + = (index + 1 + = "title:" + item. title + "<br/>" + = "Date:" + item. date + "<br/>" "# divTip"

Call:

$("#Button1").click("news1.js"

① Method

  • $. Get (url, [data], [callback], [type])
  • $. Post (url, [data], [callback], [type])

Parameter description: The url indicates the data address to be requested, the data indicates that the address sent to the server is in the key/value format, and the callback indicates the callback function executed after the request is successful; type is the format of the returned data, such as html, json, and xml.

NOTE: If data contains a Chinese format, use the encodeURI () method for transcoding. When receiving data from the client, use the decodeURI () method for decoding.

② Difference:

The $. get and $. post methods are slightly different. The main differences are as follows:

  • $. Get is not suitable for transferring data with a large amount of data. $. post does not have this restriction.
  • $. Get request results are cached in the browser, while $. post results are not cached in the browser.

③ Instance:

<script type="text/javascript">"#Button1").click(() {                                 $.get("UserInfo.aspx""#txtName""#divTip"                    .html(data); </script>

① Method

$. Ajax ([options]) is a relatively underlying asynchronous call method. The options parameter is in the key/value format and contains both the settings for sending requests and the corresponding callback data.

Note that the Jsonp method is used for cross-origin calls.

Related Article

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.