I had this error and fixed it by adding the guard on readyState
and status
shown here:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Your code here
}
};