angularjs中的奇怪行为

时间:2016-06-12 11:44:53

标签: angularjs

我有一个主页,显示从$ http.get函数获取的数据集。

好吧,第一次加载页面时,它显示得很完美,但如果你重新加载页面,就会出现以下错误:

  

angular.js:13550 SyntaxError:意外的令牌<在JSON的位置695       在Object.parse(native)

现在,如果我转到另一个页面并返回主页,它可以正常工作。如果我再次重新加载,则会出现同样的错误。

我正在努力猜测发生了什么。

这里我发布了init函数:

   $scope.init = function() {
      functions.loading($scope.loading, true);
      $scope.$on('loading', function(evt, value) {
          $scope.loading.state = value;
      });
      angular.element(document).ready(function () {
          searchService.search_stats().then( function(response) {
              FusionCharts.ready(function(){
                  var last7days = new FusionCharts({
                    "type": "column2d",
                    "renderAt": "last7days",
                    "width": "100%",
                    "height": "300",
                    "dataFormat": "json",
                    "dataSource": {
                      "chart": {
                          "caption": "Volume of Searches - Graph",
                          "subCaption": "Last 7 days",
                          "xAxisName": "Last 7 days",
                          "yAxisName": "Volume of searches",
                          "theme": "fint"
                       },
                      "data": response.data.last7days
                    }
                  });
                  last7days.render();

                  var search_countries = new FusionCharts({
                      "type": "maps/world",
                      "renderAt": "search_countries",
                      "width": "100%",
                      "height": "400",
                      "dataFormat": "json",
                      "dataSource": {
                          "chart": {
                              "caption": "Search Volume by Country - Graph",
                              "subcaption": "Last 7 days ",
                              "entityFillHoverColor": "#cccccc",
                              "numberScaleValue": "1,1000,1000",
                              "numberScaleUnit": "K,M,B",
                              "numberPrefix": "$",
                              "showLabels": "1",
                              "theme": "fint"
                          },
                          "colorrange": {
                              "minvalue": "0",
                              "startlabel": "Low",
                              "endlabel": "High",
                              "code": "#e44a00",
                              "gradient": "1",
                              "color": [
                                  {
                                      "maxvalue": response.data.max/2,
                                      "displayvalue": "Average",
                                      "code": "#f8bd19"
                                  },
                                  {
                                      "maxvalue": response.data.max,
                                      "code": "#6baa01"
                                  }
                              ]
                          },
                          "data": response.data.countries
                      }
                  });
                  search_countries.render();
                  functions.loading($scope.loading, false);
              });
          });
          functions.containerResize();
      });

search_stats 在工厂中:

      search_stats: function(a) {
          return $http.get('/api/myFunctions/search_stats/', {cache:false});
      }

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

那么,

现在,至少,我可以猜到发生了什么。

对于某些奇怪的情况,Chrome已激活开发模式,当关闭它时,页面工作正常,现在不会出现错误。