Grammar
$ (selector). Load (url,data,callback);
- The required URL parameter specifies the URL that you want to load.
- The optional data parameter specifies the collection of query string key/value pairs that are sent with the request.
- The optional callback parameter is the function name that is executed after the load () method completes.
Loading text into the specified element
$ ("button"). EQ (0). Click (function () { $ ("div "). Load ("text.txt");});
Find an interesting question:
Normal txt text
The swallow went, and when he came again, the willow withered, and when it was green, the peach Blossom thanked, and there was another time to open. But, wise, do you tell me why our days are gone? Someone stole them: who was that? And where is it hidden? They ran away: Where are they now? I don't know how many days they have given me, but my hand indeed is gradually empty. In silence counted, more than 8,000 days have slipped from my hands, like a drop of water on the tip of the sea, my days drip in the stream of time, no voice and no shadow. I couldn't help but cencen my head and tears welling. Go in spite of go, come in spite of, go to the middle, what kind of hurried? When I woke up in the morning, the hut shot into the two or three-square slanting sun. The sun he has feet ah, quietly moved, I also blankly follow the rotation. So--When you wash your hands, the days pass through the basin, and when you eat, the days pass from your bowl, and when you are silent, you pass by the eyes of the condensate. I was aware that he had gone in a hurry, and when he stretched out his hand to cover his arms, he went over from the cover-and-arm, and, as it was dark, as I lay in bed, he came crashing from me and flew away from my feet. When I opened my eyes and saw the sun, this counted and slipped away. I sighed with my face. But the shadow of the new day began to flash in the sigh. What can I do in the world of thousand doors in the days of flying away? Only wandering, only hurriedly, in more than 8,000 days in a hurry, in addition to wandering outside, what is left? The days of the past, such as light smoke, were blown away by the breeze, such as mist, steamed by the first Yang; what traces do I keep? Did I ever leave a trace like a spring? I come to this world naked, and I will go back naked in the blink of an eye. But can not be flat, why do you want to go in vain? You are clever, tell me, why are our days gone?
But this text can be added to HTML tags
<p> swallows Go, there is time to come again, Willow withered, there is no time for green, peach blossom Thanks, there is a time to open again. But, wise, do you tell me why our days are gone? Someone stole them: who was that? And where is it hidden? They ran away: Where are they now? </p><p><b> I don't know how many days they gave me, but my hand indeed is gradually empty. In silence counted, more than 8,000 days have slipped from my hands, like a drop of water on the tip of the sea, my days drip in the stream of time, no voice and no shadow. I couldn't help but cencen my head and tears welling. The </b></p><p> went, despite the coming, to come in the middle, and how hastily? When I woke up in the morning, the hut shot into the two or three-square slanting sun. The sun he has feet ah, quietly moved, I also blankly follow the rotation. So--When you wash your hands, the days pass through the basin, and when you eat, the days pass from your bowl, and when you are silent, you pass by the eyes of the condensate. I was aware that he had gone in a hurry, and when he stretched out his hand to cover his arms, he went over from the cover-and-arm, and, as it was dark, as I lay in bed, he came crashing from me and flew away from my feet. When I opened my eyes and saw the sun, this counted and slipped away. I sighed with my face. But the shadow of the new day began to flash in the sigh. </p><p> What can I do in the world of thousand doors in the days of flying away? Only wandering, only hurriedly, in more than 8,000 days in a hurry, in addition to wandering outside, what is left? The days of the past, such as light smoke, were blown away by the breeze, such as mist, steamed by the first Yang; what traces do I keep? Did I ever leave a trace like a spring? I come to this world naked, and I will go back naked in the blink of an eye. But can not be flat, why should be in vain to go this one? </p><p> you clever, tell me, why are our days gone? </p>
Tested:
- TXT text, multiple spaces and carriage returns are combined into 1 spaces;
- HTML tags work, such as <b>, <br>
$ ("div"). Load ("text.txt b");
Loads the contents of the <b> tag in a text document into the specified element.
The optional callback parameter specifies the callback function to be allowed after the load () method completes. The callback function can set different parameters:
- Responsetxt-Contains the contents of the result when the call succeeds
- Statustxt-Contains the state of the call
- XHR-Contains XMLHttpRequest objects
$ ("div"). Load ("text.tt b", function (ResponseText, StatusText, XHR) { if"success") { Console.log ( ResponseText); Console.log (xhr.status); Console.log (Xhr.statustext); } if " Error " ) { console.log (xhr.status); Console.log (Xhr.statustext); }});
Jquery-ajax load ()