Codice: Seleziona tutto
<script>
(function() {
PXHR = function() {
try { this.original = new XMLHttpRequest; } catch (e) {}
if(!this.original) try { this.original = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) {}
if(!this.original) try { this.original = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {}
if(!this.original) try { this.original = new ActiveXObject('Msxml2.XMLHTTP.4.0'); } catch (e) {}
var pxhr = this;
this.original.onreadystatechange = function() {
pxhr._updateProps();
return pxhr.onreadystatechange ? pxhr.onreadystatechange() : null;
};
this._updateProps();
}
PXHR.prototype =
{
abort: function() { return this.original.abort();},
getAllResponseHeaders: function() {return this.original.getAllResponseHeaders();},
getResponseHeader: function(header) {return this.original.getResponseHeader(header);},
overrideMimeType: function(){return this.original.overrideMimeType()},
send: function(data) {return this.original.send(data);},
setRequestHeader: function(header, value) {return this.original.setRequestHeader(header, value);},
open: function(method, url, async, username, password)
{
if(method.toLowerCase() == 'get' && this.sameServer(url) && !url.contains('csrftoken'))
{
if(url.contains('?'))
{
url += '&csrftokenAjax=1&csrftoken='+this.getToken();
}
else
{
url += '?csrftokenAjax=1&csrftoken='+this.getToken();
}
}
if (username)
{
return this.original.open(method, url, async, username, password);
}
return this.original.open(method, url, async);
}
}
PXHR.prototype.onreadystatechange = function() {}
PXHR.prototype._updateProps = function() {
this.readyState = this.original.readyState;
this.timeout = this.original.timeout;
this.upload = this.original.upload;
this.withCredentials = this.original.withCredentials;
if (this.readyState == 4) {
this.response = this.original.response;
this.responseText = this.original.responseText;
this.responseType = this.original.responseType;
this.responseXML = this.original.responseXML;
this.status = this.original.status;
this.statusText = this.original.statusText;
}
}
//external vars: server,csrftoken
PXHR.sameServer = function (path)
{
return path.toLowerCase().contains(server) || !path.toLowerCase().contains('http');
}
PXHR.getToken = function()
{
return csrftoken;
}
window.XMLHttpRequest = PXHR;
})();
</script>
Codice: Seleziona tutto
this.original.onreadystatechange = function() {}