Javascript 在Angular中用本地json替换外部JSONP
我将在与此Angular应用程序相同的服务器上存储一个json文件,我想知道如何更改此代码以读取本地存储的json文件:Javascript 在Angular中用本地json替换外部JSONP,javascript,json,angularjs,Javascript,Json,Angularjs,我将在与此Angular应用程序相同的服务器上存储一个json文件,我想知道如何更改此代码以读取本地存储的json文件: ergastAPI.getDrivers = function() { return $http({ method: 'JSONP', url: 'http://somedomain.com/datafile.json?callback=JSON_CALLBACK' }); } 我的Json文件将存储在http://mysite.com/app/j
ergastAPI.getDrivers = function() {
return $http({
method: 'JSONP',
url: 'http://somedomain.com/datafile.json?callback=JSON_CALLBACK'
});
}
我的Json文件将存储在http://mysite.com/app/js/datafile.Json,而应用程序的其余部分将存储在其父文件夹app中
我必须将方法更改为jsonp以外的其他方法吗?您需要更改方法以获取,我认为您必须将responseType更改为“JSON”或类似的内容。(我现在正在打电话,请原谅我的简短)如果是同一个域,您只需使用$http.get即可
ergastAPI.getDrivers = function() {
return $http.get('app/js/datafile.json');
}