繁体   English   中英

Angular Factory返回index.html作为response.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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM