Making an XMLHttpRequest (AJAX request) enables JavaScript code to make asynchronous HTTP requests to the server. Creating the XMLHttpRequest object via standard JavaScript quickly turns into a lengthy bit of code. This is where JavaScript’s beautiful cousin steps in: jQuery.
jQuery Makes Writing JavaScript Easier
With jQuery, we can create our XMLHttpRequest in just under 10 lines of code:
$.ajax({
var rand = Math.round(Math.random() * 999999);
type: "POST",
url: "ajax-page.php",
data: "name=Eric&location=Ohio&rand=" + rand,
success: function(msg) {
alert(msg);
}
});
Stupid Internet Explorer
If you’re using the GET method when submitting via AJAX, Internet Explorer may try to cache your request. We have solved this issue by adding a random number to the end of our query string as referenced in the example above.