I think file:// should be a first class citizen when it comes to xhr (local 
page loading local .xml file for example).

However, currently, there are some interoperability problems.

1. XHR doesn't work on local pages in IE. You get "Access is denied".

2. For open("GET", "non-existent.xml"):

Firefox: Throws NS_ERROR_DOM_BAD_URI and .readyState stops at 1.

Safari: Doesn't throw and .readyState stops at 1.

Opera: Doesn't throw and .readyState stops at 4.

3. readyState changes for found local file:

Firefox: 1, 2, 3 ,4 ,1

Opera: 1, 2, 3, 4

Safari: 1, 2, 3, 4

4. status changes inside onreadystaechange for found local file:
try {
    alert(this.status);
} catch (err) {
    alert(err);
}

Opera: invalid state error, invalid state error, 0, 0

Safari: invalid state error, 0, 0, 0

Firefox: 0, 0, 0, 0, 0

5. In http, you can do if (this.readyState === 4 && this.status === 200). 
However, for file://, you have to do (this.readyState === 4 && (this.status === 
200 || document.location.protocol === "file:") or assume this.status of 0 means 
"file:".

It'd be cool if browsers would match each other (including IE supporting xhr 
for file://) and either throw an exception for file not found like Firefox does 
or simulate http statuses for local files (200 and 404 for example), or some 
combo so a page will work locally and on the server without change.

-- 
Michael

Reply via email to