[whatwg] XMLHttpRequest for missing file

Thomas Broyer t.broyer at gmail.com
Thu Jun 28 23:37:17 PDT 2007


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
name: NS_ERROR_FILE_NOT_FOUND

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>
<script>
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);
    xhr.send(null);
    if (xhr.readyState == 4)
        alert(xhr.status);
} catch (e) {
    for (var i in e)
        document.write(i + ': ' + e[i] + '<br>');
}
</script>
<iframe src="file://C|/nonexistentfile"></iframe>

-- 
Thomas Broyer


More information about the whatwg mailing list