I am able to run my backbone js project on localhost, but when i run index.html page directly it is giving access-control-allow-origin error only in chrome browser, in firefox it is working fine in both the cases.
Asked
Active
Viewed 1,234 times
1 Answers
1
I assume that you have ajax requests to sync the Backbone Models with the server, and when you say "on localhost" you mean "with a server running on my localhost and my browser connects to 127.0.0.1:<someport>
", and when you say, "run index.html directly" you mean "launch it in the browser as file://path/to/index.html
, correct?
If I recall correctly, Chrome does not allow you to access file:
URLs via ajax as if they were network requests. Firefox did that for some release (cannot recall which at the moment), but there was pushback, it was made an option, then they reenabled it (based on my recollection).
Just run it with a server locally, using nodejs
or thin
or whatever language your server is written in.

deitch
- 14,019
- 14
- 68
- 96
-
thanks for responding deitch, What you are assuming is correct, but my application requirement is i have to place my html and javascript files in android container where the web view is chrome and where i cannot connect to server. Please provide any suggestions in this regard. – Kiran Kumar Aug 06 '13 at 13:36
-
Chrome will happily load your JS and HTML from `file://` URLs, but it won't happily let your ajax requests go through. Even if it did, the most you could do is `GET`, since `PUT` `POST` and `DELETE` have no meaning in a `file:` URL anyways. – deitch Aug 06 '13 at 13:38
-
Currently its not loading. I am using requirejs to load files, is that makes any problem. – Kiran Kumar Aug 06 '13 at 14:07
-
It might. Can you post a gist? – deitch Aug 06 '13 at 15:52
-
here I'm loading the app-index.html dynamically and accounts.js from require (defined in view). I thing the issue with the require text. – Kiran Kumar Aug 09 '13 at 16:29
-
OK, I am going to drive you a little crazy (really sorry)... can you replicate it in a jsfiddle? gist is nice, but jsfiddle is truly live. – deitch Aug 10 '13 at 17:52