Did I miss anything with this $http.jsonp in angularjs? -


i know question has been asked several times, i'm not understanding if missed or it's server thing. need show code checking please:

(function(){  var app = angular.module('c4s', ['ionic', 'starter.controllers', 'starter.services']);  app.controller('curiousctrl', function($http, $scope){     $scope.stories = [];      $http.jsonp('http://curious4science.com/?json=1&callback=json_callback')          .success(function(response) {             angular.foreach(response.data.children, function(child){                 console.log(response);                 $scope.stories.push(child.data);             });         }); });  app.run(function($ionicplatform) {   $ionicplatform.ready(function() {      if (window.cordova && window.cordova.plugins && window.cordova.plugins.keyboard) {       cordova.plugins.keyboard.hidekeyboardaccessorybar(true);     }     if (window.statusbar) {       // org.apache.cordova.statusbar required       statusbar.stylelightcontent();     }   }); })  .config(function($httpprovider, $stateprovider, $urlrouterprovider) {         delete $httpprovider.defaults.headers.common['x-requested-with'];         $stateprovider        // setup abstract state tabs directive         .state('tab', {         url: "/tab",         abstract: true,         templateurl: "templates/tabs.html"   })    // each tab has own nav history stack:    .state('tab.dash', {     url: '/dash',     views: {       'tab-dash': {         templateurl: 'templates/tab-dash.html',         controller: 'dashctrl'       }     }   })    .state('tab.chats', {       url: '/chats',       views: {         'tab-chats': {           templateurl: 'templates/tab-chats.html',           controller: 'chatsctrl'         }       }     })     .state('tab.chat-detail', {       url: '/chats/:chatid',       views: {         'tab-chats': {           templateurl: 'templates/chat-detail.html',           controller: 'chatdetailctrl'         }       }     })    .state('tab.account', {     url: '/account',     views: {       'tab-account': {         templateurl: 'templates/tab-account.html',         controller: 'accountctrl'       }     }   });    // if none of above states matched, use fallback   $urlrouterprovider.otherwise('/tab/dash');  }); }()); 

and i'm getting error:

typeerror: response.data undefined

first, tried $http.get(....) got error cross domain thing not allowed. tried jsop.

thank you.

the sucess() callback doesn't take http response argument. takes response data, status, headers, config.

so code should be

$http.jsonp('http://curious4science.com/?json=1&callback=json_callback')     .success(function(data) {         angular.foreach(data.children, function(child){             console.log(response);             $scope.stories.push(child.data);         });     }); 

(assuming returned json has children field array, , each child has data field, of course).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -