Quantcast
Channel: AjaxControlToolkit Work Item Rss Feed
Viewing all articles
Browse latest Browse all 4356

Commented Issue: XmlHttpExecutor.abort() always throws an error [27071]

$
0
0
It is impossible to call [`XmlHttpExecutor.abort()`](https://msdn.microsoft.com/en-us/library/bb311006(v=vs.90).aspx) 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/
Comments: LOL. Mikhail, look here: http://forums.asp.net/t/1748098.aspx That is my post in the forum you suggested from over 3 years ago. I was directed here. The problem is most certainly with the Ajax Control Toolkit, unless this code is owned by another team: http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.debug.js If this is not a bug, then please provide sample code that calls [`XmlHttpExecutor.abort()`](https://msdn.microsoft.com/en-us/library/bb311006(v=vs.90).aspx) without throwing an error. If you can do it, I'll buy you lunch!

Viewing all articles
Browse latest Browse all 4356

Trending Articles