Created
November 2, 2019 00:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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