Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix d3.xhr for local URIs. #632

Merged
merged 2 commits into from
Jun 19, 2012
Merged

Fix d3.xhr for local URIs. #632

merged 2 commits into from
Jun 19, 2012

Conversation

jasondavies
Copy link
Contributor

It turns out there's a simple way to support almost all local file:// requests (where req.status is always 0 in current browsers). The only case where this doesn't work is when the file does actually exist but is empty.

I've tested the CORS use case in Chrome and Safari, and local xhr now works in Safari (it won't work in Chrome at the moment unless you relax the strict security settings).

The test for local URI is based on jQuery's.  Although Chrome has strict
permissions, other browsers allow local URIs to be retrieved as long as
the same-domain policy is respected e.g. Safari.

We also check for a cross-domain request as req.status === 0 means
failure in this case.
If the error flag is set, the response attribute [1] should be the empty
string or null.  So even if a request fails and the response has been
partially loaded, this logic should still work.

This check will fail for local requests where the response entity body
is the empty string, but I don't think it's possible to detect this
situation in current browser implementations. jQuery has the same issue,
for example.

[1]: http://www.w3.org/TR/XMLHttpRequest/#the-response-attribute
@geowa4
Copy link
Contributor

geowa4 commented Jun 14, 2012

+1 on the concept, and the code looks like it'll do the job.

@jasondavies
Copy link
Contributor Author

Hurrah! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants