Umair A.
Umair A.

Reputation: 6873

AJAX By File://

I have created an AJAX based app. It's working perfect when I use my Apache server as http://localhost:8081/ but when I try to directly open the .html file in browser by file:// prefix, it fails to other pages by ajax.

http://localhost:8081/ works perfect

file:///Users/devbrats/Documents/WimBim/www/index.html#Login.html it never loads Login.html inside index.html body div

why this is so?

Upvotes: 1

Views: 133

Answers (3)

Bart
Bart

Reputation: 27205

Ajax requests only work on urls from the same host as the webpage it is called from. Local files don't work because it imposes a security risk, because any site could load a local file and send it to the host.

A quick google search gave me this link: http://docs.phonegap.com/phonegap_file_file.md.html#File (Android & BB only)

http://docs.phonegap.com/phonegap_storage_storage.md.html#Storage (Android, BB, iphone)

Upvotes: 0

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

Different browsers impose slightly different limitations when it comes to running JavaScript on file:/// URLs, but in general they impose higher restrictions than when running from a webserver. Last I checked, Chrome at least disallows XHR completely in this scenario.

So yes, you're generally better off testing JS-heavy applications from an actual webserver, especially if that's where you intend to be running it eventually anyway.

Upvotes: 1

JJJollyjim
JJJollyjim

Reputation: 6207

I don't think it's possible. I always code straight from my server (which is on my development computer), or ftp into it with Shiftedit, (which is really awesome)

Upvotes: 1

Related Questions