jQuery's get()
method is a convenience function that can be used for making a simple GET
request. The following six steps show how to get started.
Take our Ajax Training course for free.
See the Course Outline and Register<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
</body>
</html>
script
element in your HTML document, write jQuery's ready()
function, which will wait until the selected object (the HTML document in this case) is ready before executing the code passed into it.
<script>
$(document).ready(function() {
});
</script>
get()
method inside the body of the function passed into the ready()
method. The only required argument is the first one, which is the URL to make the request to.
<script>
$(document).ready(function() {
$.get('users');
});
</script>
get()
:
{foo:'bar',baz:'bim' }
, or a query string, such as foo=bar&baz=bim
.$.get('users','userID=8', function(user) {
$('<h1/>').text('Welcome ' + user.firstName).appendTo('body');
},'json');
Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, XML, Windows, Java, Adobe, HTML5, JavaScript, Angular, and much more. Check out our complete course catalog.