$.get()
AJAX - with .get() - EasyProgramming.net
HTML
<!-- Easy jQuery - Learn AJAX - how to use .get() - #13 -->
<p>
Welcome to the 13th Easy jQuery Tutorial, part of <a href="http://www.easyprogramming.net">EasyProgramming.net</a>. I covered AJAX in the Easy JavaScript series. jQuery makes much of that easier. Today, we'll look at how to use the $.get() Ajax method in jQuery.
</p>
<p>
We'll be using the keyup jQuery event for this example:
</p>
<pre>
$.get(url,data, successCallbacK, dataType);
</pre>
<p>
The success callback method above is just a method that triggers when the Ajax completes successfully. You can chain on more methods at the end that will trigger when a .get() call is done, when it fails, or always runs.
</p>
<p>
A full example would look something like this:
</p>
<pre>
$.get(url,data, successCallbacK, dataType)
.done(function(){})
.fail(function(){})
.always(function(){});
</pre>
<p>
The example is pretty straight forward so let's practice below.
</p>
<h2>
Let's practice:
</h2>
<div id="output">
</div>
JavaScript
$.get('https://www.easyprogramming.net/jQuery.php', function(data){
console.log(data);
}, 'html')
.done(function(){
alert("Completed");
})
.fail(function(e){
console.log('error:');
console.error(e);
})
.always(function(){
alert("always runs");
});