2016-06-12 109 views
0

我有一個主頁,顯示從$ http.get函數獲取的一組數據。angularjs中的奇怪行爲

好,第一次加載頁面,這是完全顯示出來,但如果你重新加載頁面時,它出現以下錯誤:

angular.js:13550 SyntaxError: Unexpected token < in JSON at position 695 at Object.parse (native)

現在,如果我去到另一個網頁,然後回來首頁頁面,它工作正常。如果我再次加載,則會出現相同的錯誤。

我在努力猜測發生了什麼。

我在這裏張貼初始化函數:

$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}); 
     } 

任何想法?

+0

打開瀏覽器開發工具,單擊網絡面板,然後查看正在下載的實際JSON。 –

+1

您的請求可能有問題,並且服務器向您發送錯誤頁面,該頁面是html,因此以「<」開頭。 –

+0

@JBNizet,是的,我打開了網絡標籤,並看到沒有響應,它用大字母表示:無法加載響應數據。但如果真的有效,發生了什麼? – domoindal

回答

0

好,

現在,至少,我可以猜到發生了什麼。

對於一些奇怪的情況,在Chrome中被激活的開發模式和關閉時,頁面正常工作,現在沒有出現錯誤。