javascript - Why can't I load up a local JSON file with AngularJS $http? -


i trying load local file(todo.json) in same folder webpage following line:

$http.get("todo.json").success( function( data ){ //do logic}); 

but following error message in javascript console:

error: failed execute 'send' on 'xmlhttprequest': failed load 'file:///c:/users/quickcoder/desktop/html5apps/todo.json'. ... 

as mentioned, index.html file consisting of code in same html5apps folder todo.json. suggestions ?

i think need running webserver serves files , json file have in folder of server.

you can use server node-serve. it's easy run once installed type serve in terminal.

[...] protocol local file not http:// file://. therefore, cannot direct ajax request local file. same applies many other apis available through javascript, can request access through http protocol. because of web's security model, we'll discuss in article.

source of quote mdn


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -