如何使用http get从本地Json文件加载数据?

时间:2022-06-28 09:47:48

I am trying to load data from local json file. I have provided the reference as shown below in screen shot. But when i run the app on localhost i get the error: 404 not found.

我正在尝试从本地json文件加载数据。我提供了如下截图所示的参考但是当我在localhost上运行应用程序时,我就会得到错误:404未找到。

如何使用http get从本地Json文件加载数据?

1 个解决方案

#1


2  

remember to inject $http. i have store json file in data folder

记得注入美元http。我将json文件存储在数据文件夹中

function loadBranch(){
        $http.get('data/branchList.json').success(function(response){

            vm.branchs = response;
        })
    }

branchList.json

branchList.json

[
  {
    "name":"sam"
  }
]

NOTE: check your json file path. i think your program couldn't able to get path

注意:检查json文件路径。我认为你的程序不能找到路径

#1


2  

remember to inject $http. i have store json file in data folder

记得注入美元http。我将json文件存储在数据文件夹中

function loadBranch(){
        $http.get('data/branchList.json').success(function(response){

            vm.branchs = response;
        })
    }

branchList.json

branchList.json

[
  {
    "name":"sam"
  }
]

NOTE: check your json file path. i think your program couldn't able to get path

注意:检查json文件路径。我认为你的程序不能找到路径