Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Created November 2, 2019 00:54
Show Gist options
  • Save luisenriquecorona/ab6e77c8e583d217afcc28254d3178af to your computer and use it in GitHub Desktop.
Save luisenriquecorona/ab6e77c8e583d217afcc28254d3178af to your computer and use it in GitHub Desktop.
By far the most common technique used, XMLHttpRequest (XHR) allows you to asyn- chronously send and receive data.
var url = '/data.php';
var params = [
'id=934875',
'limit=20'
];
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4) {
var responseHeaders = req.getAllResponseHeaders(); // Get the response
headers.
var data = req.responseText; // Get the data.
// Process the data here...
}
}
req.open('GET', url + '?' + params.join('&'), true);
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); // Set a request
header.
req.send(null); // Send the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment