Angular JS返回未定义的响应

时间:2016-02-01 05:27:25

标签: angularjs

我正在尝试发出http请求并获取结果 我可以在浏览器中使用以下

进行操作
http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json?parameters={"Normalized":false,"NumberOfDays":5,"DataPeriod":"Day","Elements":[{"Symbol":"ACN","Type":"price","Params":["c"]}]}

但是当我执行以下代码时,返回的响应是未定义的。你能告诉我我在这里做错了吗

var test = JSON.stringify({"Normalized":false,
                           "NumberOfDays":5,
                           "DataPeriod":"Day",
                           "Elements":[{"Symbol":"ACN",
                            "Type":"price",
                            "Params":["c"]
                  }]
    });

console.log(test);
$http({
        url:"http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json",
method : "GET",
parameters: test
    }).then(
        /* success */
        function(response) {
            var stock = {};
            stock = angular.fromJson(response);
            var Data = stock.Dates;
            console.log(Data);
            $scope.content = response.data;
            $scope.statuscode = response.status;
            $scope.statustext = response.statustext;
            console.log('success');
        },
        /* failure */
        function(result) {
            console.log('error');
        });

请指导我

1 个答案:

答案 0 :(得分:0)

您的Content-Type响应标头未正确设置。

检查响应标头中的Content-Type是否为application/json

目前它看起来像Content-Type:text/javascript; charset=UTF-8

因此,您的响应未以JSON格式收到。请检查正确的JSON编码