I think I found the problem. I had ng-controller specified multiple times in the same page as it was suggested. Moved it to the top, no more multiple hits.
On Fri, Sep 12, 2014 at 12:11 PM, Michael Hopper <[email protected]> wrote: > Try adding some $log.info() or console.log() statements in various places > to see what is going on. Add log statements to the beginning of the > controller to see if the controller gets created twice. Also add log > statements to AirportService (above the return) and > insideAirportReturn.getData function. > > On Friday, September 12, 2014 12:16:29 PM UTC-4, mark goldin wrote: >> >> The server gets hit twice. >> >> >> On Friday, September 12, 2014 10:34:43 AM UTC-5, Eric Eslinger wrote: >>> >>> I had problems like that when I attached the same controller to multiple >>> viewports on the same page (using ui-router), so I'm not sure if that's the >>> thing. Where'd you put the console.log command to output that info? Have >>> you confirmed on the server side, or in the network tab of the debug tools >>> that the $http service is getting hit twice for certain? >>> >>> e >>> >>> On Fri, Sep 12, 2014 at 7:53 AM, mark goldin <[email protected]> wrote: >>> >>>> In the Console it says: >>>> XHR finished loading: GET ...... >>>> XHR finished loading: GET ...... >>>> >>>> Two identical lines. >>>> >>>> On Friday, September 12, 2014 9:52:10 AM UTC-5, Eric Eslinger wrote: >>>>> >>>>> Is one of the two hits an OPTIONS request? If so, that's the CORS >>>>> preflight. >>>>> >>>>> e >>>>> >>>>> On Fri, Sep 12, 2014 at 7:16 AM, mark goldin <[email protected]> >>>>> wrote: >>>>> >>>>>> Service: >>>>>> var myModule = angular.module('motoAdsApp', []); >>>>>> myModule.factory("AirportService", function ($http, $q) { >>>>>> return { >>>>>> getData : function(dateFrom, dateTo){ >>>>>> var deferred = $q.defer(); >>>>>> var response = $http({ >>>>>> method: "get", >>>>>> crossDomain: true, >>>>>> dataType:"xml", >>>>>> contentType: "application/xml", >>>>>> url: "http://localhost/SomePage?parameters >>>>>> }); >>>>>> response.success(function (data) { >>>>>> deferred.resolve(data); >>>>>> }); >>>>>> response.error(function (data) { >>>>>> alert('Error'); >>>>>> }); >>>>>> // Return the promise to the controller >>>>>> return deferred.promise; >>>>>> } >>>>>> } >>>>>> }); >>>>>> >>>>>> Controller: >>>>>> var motoAdsApp = angular.module("motoAdsApp"); >>>>>> motoAdsApp.controller('AirportControllers', function($scope, $http, >>>>>> AirportService) { >>>>>> var result = AirportService.getData('09/07/2014', >>>>>> '09/14/2014').then(function(data) { >>>>>> var json = $.xml2json(data); >>>>>> $scope.airports = json.testData; >>>>>> }); >>>>>> >>>>>> ....... >>>>>> >>>>>> The server gets hit twice when I load the page. Any idea why? >>>>>> >>>>>> Thanks >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "AngularJS" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to [email protected]. >>>>>> To post to this group, send email to [email protected]. >>>>>> Visit this group at http://groups.google.com/group/angular. >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> >>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "AngularJS" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at http://groups.google.com/group/angular. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- > You received this message because you are subscribed to a topic in the > Google Groups "AngularJS" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/angular/r9mM2nIpXzk/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
