Cai Zhi, a rookie, reviews part 2 of Ajax (the load () method in jQuery implements Ajax functions)

Time:2021-10-25

In the last blog, I wrote about using XMLHttpRequest object to load data asynchronously in traditional JavaScript. Alas, children’s shoes… Is it a headache to see those codes! Hehe… Not only you, but also I am a little disgusted. We should not only judge the browser, but also… Anyway, there is a big lump of code, which looks not cool. Now, let’s forget to take a big lump (remember: it’s not really forgotten here! It seems that when many companies interview Ajax, they will let you write an original Ajax program without dragging controls, so its importance, you know!)! Well, after saying so much, you should “forget” you! Ha ha… The time to witness miracles has come (woo… Don’t say I’m bragging! It’s not what I said, it’s what Liu Qian said. Find him for anything!)! In jQuery, you can easily use the load () method to obtain asynchronous loading data. Now let a few lines of code replace this big lump! (first, as before, create two pages, 1.htm and 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: don’t forget to add this!
<script type=”text/javascript”>
$(function () {
$(“#btnget”). Click (function() {/ / button click event
$(“#divMsg”).load(“2.htm”);// Call the load () method; Load syntax format: load (URL, [data], [callback]): where URL is the address of the loaded page; The optional parameter data is the data to be sent to the server / / in the format of a key / value; Callback is the callback function returned to the loading page after loading successfully
})
}) / / you must pay attention here! Brackets must be typed “in pairs at the same time”. When you write too much code, you will make mistakes if you are not careful at this point!
</script>
</head>
<body>
< input type = “button” value = “get data” / >
<div>
</div>
</body>
</html>

The code in 2.htm is as follows:

Copy codeThe code is as follows:
<head>
<title></title>
</head>
<body>
Name: side dish < br / >
Gender: male < br / >
Email: [email protected]
</body>
</html>

After writing, I hope you don’t laugh here! Because I’m Cai niucai originally. What I write is a little different. Just review it for myself!

Recommended Today

Python data processing in the third stage of employment class

Chapter 1 Introduction to pandas 1.1 / 1.2 jupyter Foundation Create virtual environment a. Create a virtual environment for the specified Python version conda create -nEnvironment variable name python = 3.6 b. Virtual environment command conda env list ——View * * currently owned virtual environments conda remove-N environment variable name — all——delete*Environmental variables activateEnvironment variable […]