I've made small async GET request to my server with vanilla js.
var rReq = new XMLHttpRequest();
rReq.onload = function (e) {
window.updateCartnRows(e.target.response);
};
rReq.open('GET', '/usr/cart/xhrRemoveItemsByType/' + type, true);
rReq.responseType = 'text';
rReq.send();
From the client's point of view it works as expected, but my server doesn't treat it as async request, it fails xhr check if I set it.
Equal Jquery request works fine:
$.get('/usr/cart/xhrRemoveItemsByType/' + type, function (e) {
console.log(e);
window.updateCartnRows(e);
});
The difference in X-Requested-With "XMLHttpRequest" http header, which had been set by default in Jquery request. I found that vanilla js query can be fixed with this line:
rReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
But I'm in doubt about this solution as in documentation (e.g. MDN) nothing mentioned about necessity to set this header, just true parameter for async in XMLHttpRequest.open() method.