angularjs - Angular REST cannot return simple data -


i trying $http rest call working in appgyver project working nothing seems come right, returns error.

please note angular app running on mobile devices , connect remote web service.

i've double checked custom api working , returning data correctly in number of ways, namely:

  • hard coded curl request running sh files in terminal - returns data , correct 200 code
  • tested api end points in both postman , firefox's soa client.

putting in test end point of http://somesite.com/quote-and-buy-performance/druidapi/taxonomy_term returns data below:

[{"tid":"1","vid":"2","name":"acme ltd.","description":"","format":"filtered_html","weight":"0","parent":"0","uri":"http://somesite.com/quote-and-buy-performance/druidapi/taxonomy_term/1"},{"tid":"2","vid":"2","name":"abc films ltd","description":"","format":"filtered_html","weight":"0","parent":"0","uri":"http://somesite.com/quote-and-buy-performance/druidapi/taxonomy_term/2"}] 

even simple csrf token request gives me errors.

could possibly point out going wrong here, appgyver site badly documented , have tried angular restful sample code below based upon https://docs.angularjs.org/api/ng/service/$http , https://docs.angularjs.org/api/ng/service/$http#setting-http-headers

please note code below angular.js using javascript syntax (as opposed coffeescript), logging output follows code

angular .module('main') .controller('logincontroller', function($scope, supersonic, $http) {     $scope.navbartitle = "settings";      $scope.stoken = "response goes here";      $scope.processlogin = function(){         var csrftoken;          steroids.logger.log("start call: processlogin");          // $form_login_email_address = $scope.login_email;         // $form_login_password = $scope.login_password;          $local_get = "http://somesite.com/quote-and-buy-performance/services/session/token";         $hal_get_taxterm_index = "http://somesite.com/quote-and-buy-performance/druidapi/taxonomy_term";          // $http.defaults.headers.common.contenttype('application/json');          var req = {             method: 'get',             url: $hal_get_taxterm_index,             headers: {                 'content-type': 'application/json'             }         }          $http(req)           .success(function(data, status, headers) {             steroids.logger.log("inside http.get() success");         }).error(function(data, status, headers){             steroids.logger.log("inside http.get() error");             steroids.logger.log('data: ' + data);             steroids.logger.log('status: ' + status);         }).then(function(data, status, headers){             steroids.logger.log("inside http.get() then");         });          steroids.logger.log("end call: processlogin");     }  }); 

logging output calls steroids.logger.log

view        time            level   message main#login  16:01:55.219    info    "inside http.get() error" main#login  16:01:55.219    info    "data: null" main#login  16:01:55.219    info    "status: 0" main#login  16:01:55.64     info    "end call: processlogin" main#login  16:01:55.64     info    "start call: processlogin" 

here's do:

separate out http call service. pretty standard way modularize code in angular:

angular.module('main').factory("someservice", function($http) {   return {     get: function() {       $http({         url: "http://somesite.com/quote-and-buy-performance/druidapi/taxonomy_term",         method: "get",         headers: {           "content-type": "application/json"         }       }).success(function(data, status, headers, config) {         console.log("success!");         console.log(data);       }).error(function(data, status, headers, config) {         console.log("error!");         console.log(status);         console.log(data);       });     }   } }) 

then use in controller, include in controller declaration , call normal method:

angular.module('main').controller('logincontroller', function($scope, supersonic, someservice) {   $scope.navbartitle = "settings";   $scope.stoken = "response goes here";   $scope.processlogin = function(){     var csrftoken;     steroids.logger.log("start call: processlogin");      someservice.get();      steroids.logger.log("end call: processlogin");   } }) 

do , comment results , can work there.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -