[whatwg] XMLHttpRequest for missing file

2007/6/29, Geoffrey Garen:
> The XMLHttpRequest spec has this to say about failed loads:
> <snip>
> The NETWORK_ERR exception is thrown when a network error occurs in
> synchronous requests.
> ...
> In case of network errors
> In case of DNS errors or other type of networks run the following set
> of steps.This does not include HTTP responses that indicate some type
> of error, such as HTTP status code 410.
> </snip>
> What should happen with failed file:/// URL loads? For example, what
> if the file doesn't exist?

I'd personnaly like the browser emulates a 404, but that's not what
browsers do today:

Firefox raises an exception:
QueryInterface: function QueryInterface() { [native code] }
message: Component returned failure code: 0x80520012
(NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]
result: 2152857618

IE7 too:
name: TypeError
message: Acc?s refus?.
number: -2147024891
description: Acc?s refus?.

Opera doesn't raise an exception. The status is "0" !?

Safari 3 for Windows raises this exception:
message: NETWORK_ERR: XMLHttpRequest Exception 101
code: 101
line: 10
sourceURL: file:///C:/Documents%20and%20Settings/tbr/Mes%20documents/Mes%20Projets/test.html

Test file:
<!doctype html>
var xhr;
if (window.XMLHttpRequest)
    xhr = new XMLHttpRequest();
else if (window.ActiveXObject)
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
try {
    xhr.open("GET", "file:///C|/nonexistentfile", false);
    if (xhr.readyState == 4)
} catch (e) {
    for (var i in e)
        document.write(i + ': ' + e[i] + '<br>');
<iframe src="file://C|/nonexistentfile"></iframe>

Thomas Broyer

Received on Thursday, 28 June 2007 23:37:17 UTC