Angular工厂返回index.html作为响应.data而不是JSON
Angular Factory returning index.html as response.data instead of JSON
我在这个问题上迷路了。
我已经设置了一个productFactory,这意味着$http.get
硬编码JSON数据。此JSON已被JSONlint验证。
返回的数据不是这个数据,而是我的index.html文件。是什么原因造成的呢?
productFactory:
angular.module('APP').factory('productFactory', function($http) {
var productFactory = {
getProducts:function(){
return $http.get('/public/data/product.json')
.then(function(response) {
console.log(response);
return response;
});
},
}
return productFactory;
})
记录到控制台的响应是我的整个index.html文件的字符串版本
/public/
实际上是文件路径的一部分吗?通常公共文件夹被设置为文档根目录,实际上不会出现在任何资源的路径中。
尝试在浏览器中查看product.json
,并确保Angular在同一路径上调用GET
。
你试过吗?
angular.fromJson(response);
相关文章:
- 使用$http的angular js中的JSON数据-data.push()
- 自定义筛选器不'我不使用django数据表视图创建的ajax.data.Json
- Highchart and json data
- 一个data.json被多个源访问和更改
- JSON.parse(data) return [undefine]
- jQuery $.each loop and json mysql data
- 如何在 JavaScript 中访问 data.submit() 的 json 响应对象
- javascript foreach on array / json data 但按最新日期排序
- 使用 Ember Data 检索 json 文件
- Jquery POST JSON data to Python backend
- JSON Data using ember.js
- Angularjs on JSON data
- Javascript data input Json
- Javascript HTTP POST with JSON data
- javascript Highcharts JSON data to HTML table
- Formatting response JSON data using AngularJS & ExpressJ
- 为什么我们在从ajax json调用获取响应时使用data.d
- 从data.json中提取随机数据并对其进行混洗
- 我想写一个异步JSON联系人,它将覆盖我的data.JSON文件的内容
- 加载点击 jquery data json