FAQ Database Discussion Community


Angularjs does not post JSON data to REST API

angularjs,angularjs-http
I am new to AngularJS. I am trying to post data to a local server. Below is the code. var postObject = new Object(); postObject.email = "emailtobesaved1"; postObject.userData ="userDatatobeSaved"; var s=JSON.stringify(postObject); $http({ url: 'http://localhost:8080/people', dataType: 'json', method: 'POST', data: s, headers: { "Content-Type": "application/json" } }).success(function(response){ $scope.response = response; }).error(function(error){...

AngularJS, $http.get() and “controller as”

javascript,angularjs,angularjs-http
I'm pretty new to the whole AngularJS world and how it works, however I am struggling to get it working as expected. I know that its something to do with the way I am using $http.get() and trying to assign the variables back to my controller, but I just can't...

AngularJS $httpProvider Error

angularjs,gulp,angularjs-service,angularjs-factory,angularjs-http
I'm writing a web application in AngularJS with Django API endpoints. When I want to perform a JSON call to this endpoints, I want to catch possible errors (such as 404 not found error). For this, I'm using $httpProvider. But when I run my application (using gulp), in the console,...

Working with APIs in AngularJS

angularjs,api,angularjs-directive,angularjs-service,angularjs-http
I'm trying to create a layout that displays 'channel' data for multiple 'users'. The API I'm using requires one to query first to get a list of username and then another query for each user to get the channel information. I gave it my best shot but ended up breaking...

$http.get is undefined when $http is used outside angular code

angularjs,jasmine,karma-jasmine,angularjs-controller,angularjs-http
I am running jasmine unit test against a method which is outside angular controller. Running the jasmine throws the following error, TypeError: Cannot read property 'get' of undefined at testMethod Can anyone help me with fixing the above error. Thanks ! Test.js function testMethod() { var $http = angular.element('html').injector().get('$http'); $http.get('/testAPI/testCall').success(...);...

HTTP Get request from Angular JS receives empty reply

javascript,angularjs,asp.net-web-api,angularjs-http
Since I am fairly new to web development, this might very well be a very easy to solve question. Unfortunately I am not able to solve this myself as I have no clue on where to search. Currently I'm trying to get data out of an ASP.NET Web API that...

TypeError: (intermediate value)(intermediate value).success is not a function (angular)

javascript,angularjs,angularjs-scope,angularjs-controller,angularjs-http
I have difficulties understanding this error... I dont quite understand why its not a function.... angular.module('mkApp').factory('mkService', function ($http, $log) { function getLookUp(successcb) { $http = ({ method: 'GET', url: 'api/Entries/' }).success(function (data, status, header, config) { successcb(data); }). error(function (data, status, header, config) { $log, warn(data, status, header, config); });...

Angularjs $http.get does not work

javascript,angularjs,rest,angularjs-http
My purpose is to consume a REST web service in AngularJS and I am making some trials right now. Below code is not working and throwing following exception. Can you help me identifty the problem? Thanks in advance. function getUsersFromLocal($scope,$http) { $http.get('http://localhost:8080/people'). success(function(data) { $scope.data = data; }); return data;...

Optimize ajax calls with AngularJS [duplicate]

angularjs,angular-services,angularjs-http
This question already has an answer here: how do I trigger an angularjs service after every nth seconds a user typed something 3 answers I'm creating something like this example but for search proposes, using this code: $scope.$watch('terms', function(newValue, oldValue) { if (angular.equals(newValue, oldValue)) { return; } getResults(); //$http.get......

Javascript angular function definition [duplicate]

angularjs,jsonp,angularjs-http
This question already has an answer here: Can I avoid using global callback function when loading JSON-P? 2 answers function callbackformeetup (data) { console.log(data); } app.service('MeetupSearch', function($http){ this.search = function(zip, word){ return $http.jsonp('https://api.meetup.com/find/groups?key=111111111111&sign=true&photo-host=public&zip=80202&upcoming_events=true&text=ruby&callback=callbackformeetup'); }; }); So the above works. When I define the function above the app.service, the api...

Blank PDF returned while making a POST Request but works fine with GET

angularjs,node.js,express,wkhtmltopdf,angularjs-http
I have a AngularJs frontend and a NodeJS backend. I am trying to build a PDF on NodeJS based on some parameters from AngularJS and return the PDF in response. The code I am using seems to work fine when I make a GET request from AngularJS, but it returns...

Why return the promise and the data when using $http in an Angular service?

javascript,angularjs,angular-promise,angularjs-http
I frequently see tutorials and snippets online about Angular services to make $http calls that return both the $http promise and some data. If the promise is returned to the controller, what is the point of returning the data in the service? I don't even understand to where it is...

multiple returned keys json

javascript,angularjs,ionic-framework,angularjs-factory,angularjs-http
I have a joomla site running k2 and pulling info from it by adding format=json to the end of the string: https://www.example.com/posts?format=json which outputs something like this: { site: { url: "https://www.example.com", name: "mySite" }, category: { id: "67", name: "Gauteng", alias: "gauteng", link: "/tna/provincial/gauteng.html", parent: "66", extraFieldsGroup: "0", image:...

Angular 2: How to use/import the http module?

angularjs,angularjs-http,angularjs-2
I've been playing with Angular 2 Quickstart. How can I use/import http module in Angular 2? I've looked at Angular 2 Todo's .js, but it doesn't use the http module. I've added "ngHttp": "angular/http", to dependencies in package.json because I've heard Angular 2 is somewhat modular...

Angular $http useCredentials return error

angularjs,drupal,angularjs-http,drupal-services,angularjs-authentication
I am trying to build an AngularJS frontend for a Drupal 7 website. The problem is that, when I set useCredentails to true, I get this error. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com. This can be fixed by moving the resource to...

success and error function in the controller for a service

javascript,angularjs,angularjs-service,angularjs-http,angularjs-promise
I have the following code in a service and I am calling fetchData function from the controller. Service app.service("geturl", function($http) { urllist = []; geturl.fetchData = function() { var data = []; for (i = 0; i < urllist.length; i++) { (function(index) { return $http.get(geturl.urllist[index], { timeout: 8000 }) .then(function(response)...

angular routing with ng-include

angularjs,routing,angularjs-routing,angular-promise,angularjs-http
It's a little complex to describe my problem.Now I have two pages to be routed. One is project.jsp,the other is ticket.jsp.The latter can be included in the former using ng-include. In index.jsp,I use ng-view. index.jsp <div ng-view></div> In app.js,I do the routing config and create controllers. $routeProvider.when('/tickets', { templateUrl: 'ticket.jsp',...