In the previous blog, I wrote about using XMLHttpRequest objects to load data asynchronously in traditional JavaScript, alas, children's shoes .... See the code is not a little headache ah! Not only you, I have a little disgusted, not only to judge the browser, but also ... Anyway, there is a big piece of code, looks not cool, now, let us forget to take a big Tuo bar (remember: Here is not really forget!) It seems like many companies interviewing Ajax this piece of content, you do not have to drag the control of the way to write an original eco-Ajax program, so its importance, you understand! )! Okay, so much so, you should "forget" you! Oh...... It's time to witness the miracle (whining ...). Don't say I'm bragging! This is not what I said, this Liu Qian said, what things to find him ah! )! In jquery, using the load () method can easily achieve the ability to get asynchronous loading data, now let a few lines of code instead of this big Tuo! (First, or as before, create 1.htm and 2.htm two pages first!) )
The code in 1.htm is as follows:
Copy Code code as follows:
<title></title>
<script src= "Scripts/jquery-1.4.1.js" type= "Text/javascript" ></script>/Note: Don't forget to add it!
<script type= "Text/javascript" >
$ (function () {
$ ("#btnGet"). Click (function () {//button clicks event
$ ("#divMsg"). Load ("2.htm");//Call Load () method; Load syntax format: Load (Url,[data],[callback]): Where URL is loaded page address, optional parameter data is to be sent to the service//service, the format is a key/value;callback after the successful loading, Return to the callback function that loads the page
})
})//Here must pay attention to Oh! Parentheses must be "in the same time" well, when you write more code, at this point inadvertently will be wrong!
</script>
<body>
<input type= "button" id= "Btnget" value= "Fetch data"/>
<div id= "Divmsg" >
</div>
</body>
The code in 2.htm is as follows:
Copy Code code as follows:
<title></title>
<body>
Name: Vegetable <br/>
Sex: Male <br/>
Email: cj1161059871@163.com
</body>
Finished, here hope the heroes do not laugh Ah! Because I originally is steer Cai, write out of thing is a bit two, just give yourself a review!