jQuery .get() is used when you want to get data from a server without reloading the page. It's a part of jQuery's AJAX features, which let your webpage talk to a server in the background.
Think of it like this: you click a button, and your page secretly asks the server for some data—then shows that data right away.
Basic Syntax:
$.get(URL, callback);
Example: Load a text file and show it in a div
Let’s say you have a file called info.txt, and you want to show its content on the page:
$("#loadBtn").click(function() {
$.get("info.txt", function(data) {
$("#content").html(data);
});
});
Here’s what this does:
-
When you click the button with ID loadBtn, it sends a GET request to info.txt.
-
Once the file is loaded, it puts the text inside the element with ID content.
What Kind of Data Can You Get?
Why Use .get()?