3 ms·
Doing ajax without jQuery is also good fun var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) {
by teknologist 12y ago
Doing ajax without jQuery is also good fun
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
callback(JSON.parse(xhr.responseText));
}
};
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
And that's not taking care of errors, edge cases or Internet Explorer at all.
In jQuery:
$.post(url, data)