It is impossible to call XmlHttpExecutor.abort() without getting en error, in its current implementation. Here is the current implementation in http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.debug.js:
function Sys$Net$XMLHttpExecutor$abort()
{
/// <summary locid="M:J#Sys.Net.XMLHttpExecutor.abort" />
if (arguments.length !== 0) throw Error.parameterCount();
if (!this._started)
{
throw Error.invalidOperation(Sys.Res.cannotAbortBeforeStart);
}
if (this._aborted || this._responseAvailable || this._timedOut)
return;
this._aborted = true;
this._clearTimer();
if (this._xmlHttpRequest && !this._responseAvailable)
{
this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
this._xmlHttpRequest.abort();
this._xmlHttpRequest = null;
this._webRequest.completed(Sys.EventArgs.Empty);
}
}
Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod()
{
/// <summary locid="M:J#Function.emptyMethod" />
if (arguments.length !== 0) throw Error.parameterCount();
}
Specifically this line:
this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
Function.emptyMethod expects zero arguments and throws an error if any arguments are passed. But the onreadystatechange event will always pass an event object as an argument to its handler. This will always throw an error (unless you are using an older IE browser)!
The onreadystatechange event should not be bound to Function.emptyMethod, it should be set to null.
This code reproduces the problem:
var request = new Sys.Net.WebRequest();
request.set_url("/someUrl");
request.set_httpVerb("POST");
request.set_body("myKey=myValue");
request.invoke();
request.get_executor().abort();
To see the error, view this link with your JavaScript console open:
http://jsfiddle.net/gilly3/dcgCY/
function Sys$Net$XMLHttpExecutor$abort()
{
/// <summary locid="M:J#Sys.Net.XMLHttpExecutor.abort" />
if (arguments.length !== 0) throw Error.parameterCount();
if (!this._started)
{
throw Error.invalidOperation(Sys.Res.cannotAbortBeforeStart);
}
if (this._aborted || this._responseAvailable || this._timedOut)
return;
this._aborted = true;
this._clearTimer();
if (this._xmlHttpRequest && !this._responseAvailable)
{
this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
this._xmlHttpRequest.abort();
this._xmlHttpRequest = null;
this._webRequest.completed(Sys.EventArgs.Empty);
}
}
Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod()
{
/// <summary locid="M:J#Function.emptyMethod" />
if (arguments.length !== 0) throw Error.parameterCount();
}
Specifically this line:
this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
Function.emptyMethod expects zero arguments and throws an error if any arguments are passed. But the onreadystatechange event will always pass an event object as an argument to its handler. This will always throw an error (unless you are using an older IE browser)!
The onreadystatechange event should not be bound to Function.emptyMethod, it should be set to null.
This code reproduces the problem:
var request = new Sys.Net.WebRequest();
request.set_url("/someUrl");
request.set_httpVerb("POST");
request.set_body("myKey=myValue");
request.invoke();
request.get_executor().abort();
To see the error, view this link with your JavaScript console open:
http://jsfiddle.net/gilly3/dcgCY/