简体   繁体   English

Angular Factory返回index.html作为response.data而不是JSON

[英]Angular Factory returning index.html as response.data instead of JSON

I'm lost on this one. 我迷失了这个。

I've set up a productFactory that is meant to $http.get hardcoded JSON data. 我已经建立了一个productFactory,该产品旨在用于$http.get硬编码的JSON数据。 This JSON has been validated by JSONlint. 此JSON已通过JSONlint验证。

Instead of returning this data, the data returned is my index.html file. 而不是返回此数据,返回的数据是我的index.html文件。 What could be causing this? 是什么原因造成的?

productFactory: 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;
})

The response logged to the console is a string version of my entire index.html file. 记录到控制台的响应是我整个index.html文件的字符串版本。

Is /public/ actually a part of the path to the file? /public/实际上是文件路径的一部分吗? Usually the public folder is set up as the document root and doesn't actually appear in the path to any resource. 通常,公用文件夹被设置为文档根目录,实际上并没有出现在任何资源的路径中。

Try getting to view product.json in a browser and make sure Angular is calling GET on the same path. 尝试在浏览器中查看product.json并确保Angular在同一路径上调用GET

你试过这个吗?

angular.fromJson(response);

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

相关问题 Angular从JSON API返回空白的response.data - Angular returns blank response.data from json api GET 请求返回 index.html doc 而不是 json 数据 - GET request returns index.html doc instead of json data node.js 获取后请求返回索引。html 而不是 json - node.js fetch post request returning index.html instead of json Nancy响应未返回index.html的正确MIME类型,包括 - Nancy response not returning proper MIME Type for index.html including POST请求返回index.html doc而不是反应js中的json数据 - POST request returns index.html doc instead of json data in react js 如何使用角度response.data设置DIV的backgroundImage - how to set backgroundImage of DIV using angular response.data 从response.data angular js获取特定值 - get specific value from response.data angular js 是否会将所有angular2包包括在index.html中,使导入从内存中获取数据,而不是再次从服务器请求数据? - Will including all the angular2 bundles in index.html make imports get data from memory instead of requesting it from the server again? 为什么response.data是未定义的? - Why response.data is undefined? AngularJS工厂返回State对象而不是promise中的JSON数据 - AngularJS factory returning State object instead of JSON data from promise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM