Cainiao Cai's Ajax review article 2 (Ajax function implemented by the load () method in JQuery)

Source: Internet
Author: User

In the previous blog, I wrote that the XMLHttpRequest object is used in traditional Javascript to load data asynchronously. Alas, it's a headache to see the code! Haha ...... not only are you, but I am a little disgusted, not only need to judge the browser, but also ...... there is a huge amount of code, which looks uncomfortable. Now, let's forget to take it. (remember: It's not really forgotten here! It seems that many companies don't need to drag controls to write an original Ajax program when interviewing Ajax, so it's important, you know !)! Well, after talking so much, you should "forget" it! Haha... it's time to witness a miracle (whining... don't say I'm bragging! This is not what I said. Here, Liu Qian said. What can I do to find him !)! In JQuery, the load () method can be used to easily obtain the asynchronous data loading function. Now let's replace this with several lines of code! (First, let's look at the previous example. First, we should create two pages, 1.htmand 2.htm !)

The code in 1.htm is as follows:Copy codeThe Code is as follows: <Title> </title>
<Script src = "Scripts/jquery-1.4.1.js" type = "text/javascript"> </script> // Note: Do not forget to add this!
<Script type = "text/javascript">
$ (Function (){
$ ("# BtnGet"). click (function () {// click Event
$ ("# DivMsg "). load ("2.htm"); // call the load () method; load syntax format: load (url, [data], [callback]): Where url is the page address to be loaded; the optional parameter data is the data to be sent to the server // server, in the format of a key/value. callback is the callback function returned to the loading page after the load is successful.
})
}) // Pay attention to it here! Brackets must be "paired at the same time". When you write too much code, you may encounter errors at this point!
</Script>
</Head>
<Body>
<Input type = "button" id = "btnGet" value = "Get Data"/>
<Div id = "divMsg">
</Div>
</Body>
</Html>

The code in 2.htm is as follows:

Copy codeThe Code is as follows: <Title> </title>
</Head>
<Body>
Name: coriander <br/>
Gender: male <br/>
Email: cj1161059871@163.com
</Body>
</Html>

I have finished writing. I hope you will not laugh! Because I was Cai Niu, Cai, and I wrote two things. I just want to review it for myself!

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.