Добавление события в AJAX request
день добрый!
Подскажите пожалуйста как лучше подключить скрипт по добавлению события для реквестов. Проблема в том что событие срабатывает только на первые запросы при загрузке страницы, на дальнейшие запросы уже событие не вешается. Добавление события: (function(open) { window.XMLHttpRequest.prototype.open = function(method, url, async, user, pass) { this.addEventListener("readystatechange", function() { if (this.readyState == 4 && this.status == 200) { console.log(this); } }, false); open.call(this, method, url, async, user, pass); }; })(XMLHttpRequest.prototype.open); скрипт подключается : <body onload="initSession()"> |
var xhr = new XMLHttpRequest(), method = "GET", url = "http://localhost:2998/"; xhr.open(method, url, true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { console.log(this); }; }; xhr.send(); xhr.send(); //Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED. (function (open) { XMLHttpRequest.prototype.open = function (method, url, async, fourth) { console.log(fourth) this.addEventListener("readystatechange", function () { if (this.readyState == 4 && this.status == 200) { console.log(this); } }, false); open.call(this, method, url, async, fourth); } })(xhr.open); xhr.open(method, url, true, 'fourth'); xhr.send(); xhr.open(method, url, true, 'fourth'); xhr.send(); ) Найди 10 отличий |
Часовой пояс GMT +3, время: 16:32. |