W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

Using xhr with file://

From: Michael A. Puls II <shadow2531@gmail.com>
Date: Thu, 16 Apr 2009 10:10:58 -0400
To: public-webapps@w3.org
Message-ID: <op.ushgciyk1ejg13@sandra-svwliu01>
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
Received on Thursday, 16 April 2009 14:11:36 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:31 GMT