AngularJS重复http请求 [英] AngularJS duplicates http requests
本文介绍了AngularJS重复http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在与AngularJS进行一些接口并观看Chrome控制台我检测到每个http请求都会复制到API。
有什么方法可以避免这种情况吗?
I'm doing some interfaces with AngularJS and watching the Chrome Console I detect that each http request to an API it makes for duplicate. Is there any way to avoid this?
这是我的简化代码
$http.jsonp('http://APIURL.com/api/category/menu?callback=JSON_CALLBACK').success(function(data){
$scope.categories=data.categories;
});
完整代码:
var kbControllers = angular.module('kbControllers', []);
kbControllers.controller("KBHomeController", function ($scope, $http, $rootScope) {
$rootScope.header = 'Title of page';
$http.jsonp('apicall.com/api/category/menu?callback=JSON_CALLBACK').success(function (data) {
$scope.categories = data.categories;
});
});
这是我的控制台
and this is my console
是否有任何想法?
推荐答案
我遇到了这个问题,你可以这样解决:
i have faced this problem, and you can resolve it like this :
- 检查你是否已经声明ng-controller两次,你需要声明它一次
- 检查你是否声明了data-ng-click,如果是,你需要用ng-click替换它/ li>
- check if you have declared ng-controller twice , you need to declare it just one time
- check if you have declared data-ng-click , if so , you need to replace it with ng-click
这就是它
这篇关于AngularJS重复http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文