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:
<Head>
<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:
<Head>
<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!