0

This is probably something very simple but I am having some problem making an HTTP GET request, getting the data back, and attaching it onto the javascript global window variable.

Simple HTTP Call:

    $http.get("production/dashboard?dashboard_type=A").success((data) ->
      $scope.pods = data;

      window.pods = $scope.pods.to_json;
      window.type = 'A';

      alert(window.pods)
      alert(window.type)

      alert "success1"
      return
    ).error (data, status, headers, config) ->
      return

Upon execution, I am getting:

 1. Alert("undefined")
 2. Alert("A")

I thought that the promise of the http request will get resolved when the response returns? I checked the Network tab and there is indeed JSON data being sent back as the response to the request. I must be missing something simple...

simonzhu
  • 168
  • 2
  • 8

2 Answers2

0
$http.get("production/dashboard?dashboard_type=A")
     .success(function(data) {
      $scope.pods = data;

      window.pods = $scope.pods;
      window.type = 'A';

      alert(window.pods);
      alert(window.type);

      alert("success1");
      return
   }).error (function(data, status, headers, config){
            return;
     });

This is assuming it has access to the window where your code is. Is this wrapped in a module and controller?

rleffler
  • 430
  • 6
  • 15
  • Yes. Apologies for the syntax, I was writing coffeescript. The module is in fact wrapped in a AngularJS Controller. – simonzhu Sep 26 '14 at 22:00
0

As we need json data to get from $http.. Trying putting .json like below.

$http.get('/products.json') 

Regarding your another issue.. you might get a hint with this link AngularJS : Prevent error $digest already in progress when calling $scope.$apply()

Community
  • 1
  • 1
Rahul Dess
  • 2,397
  • 2
  • 21
  • 42