Questions tagged [angularjs-http]

AngularJS tag for $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

For unit testing applications that use $http service, see $httpBackend mock.

For a higher level of abstraction, please check out the $resource service.

The $http API is based on the deferred/promise APIs exposed by the $q service. While for simple usage patterns this doesn't matter much, for advanced usage it is important to familiarize yourself with these APIs and the guarantees they provide.

General usage

The $http service is a function which takes a single argument — a configuration object — that is used to generate an HTTP request and returns a promise with two $http specific methods: .then and .catch.

// Simple GET request example :
$http.get('/someUrl')
  .then(function(response) {
    var data = response.data;
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
// Simple POST request example (passing data) :
$http.post('/someUrl', {msg:'hello word!'})
  .then(function(response) {
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

Since the returned value of calling the $http function is a promise, you can also use the then method to register callbacks, and these callbacks will receive a single argument – an object representing the response. See the API signature and type info below for more details.

A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning that the error callback will not be called for such responses.

426 questions
5
votes
3 answers

Is there an any method ordering when $q.all has multiple http call functions in Angularjs?

First of all, I am not good at angularjs. While I've been studying about $q, I faced a weird problem. When I use $q.all, I put $http in regular sequence expecting to get results in same order, but what I get was random results. See this and correct…
Canet Robern
  • 1,049
  • 2
  • 11
  • 28
5
votes
2 answers

Replacing $http with Fetch API

I'm replacing $http with Fetch API and got replaced $q with Promise API. Because of that, Angular didn't run digest cycles anymore, thus UI didn't render. To solve this problem I tried Zone.js and that seems to solve our problems partially.…
Gaui
  • 8,723
  • 16
  • 64
  • 91
5
votes
4 answers

How to skip angularjs interceptor for an HTTP request?

I have an angularjs app, in which I have an interceptor that adds the authorization token to the header of each request. However, somewhere in the application I need to use and external API where the interceptor ruins it, because it adds this…
Behrooz
  • 1,895
  • 4
  • 31
  • 47
5
votes
4 answers

Using the $q service with angular

I still can't understand the role of using the $q service, (what exactly will it add) if you want to create a service that need to call only one API via http , in this situation I don't know why shouldn't I just do the following (without using $q) :…
5
votes
1 answer

Run a hook before $resource constructs the url?

I want to programatically alter route parameters before $resource constructs the url. I cannot use angular's http interceptor to do this, since the route is already concatenated at that point. Given an Assortment.model.js module.exports =…
5
votes
2 answers

AngularJS spring security login/logout with Cross-Origin Resource Sharing (CORS)

Problem Statement: My UI app is running on 9000 port(grunt project) and my server side spring boot project running on 8421 port. I am able to hit all the URL's from my UI app except login and logout. Please let me know how can I configure spring…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
5
votes
1 answer

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

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', …
5
votes
2 answers

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

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…
Sambhav Sharma
  • 5,741
  • 9
  • 53
  • 95
5
votes
1 answer

Authenticating angular for HTTP requests on MVC4 site using Windows Authentication

I am currently developing a website using AngularJS, and the application is meant to POST and GET data to and from an already running MVC4 application. This MVC4 application is using Windows Authentication. I can access the MVC4 application…
5
votes
3 answers

$http error handling in AngularJS

$http in my AngularJS project not able to recognize 40X(401,403,405...) errors on iOS. I am using 1.2.10 AngularJS version and Cordova version 3.4.0. Below is the code I am using: TE_SERVICES.factory('hello',function ($http,$rootScope) { return…
Surya
  • 439
  • 3
  • 9
  • 31
4
votes
4 answers

Return function value from $http GET service

I am trying to return an array from a function once onClick is triggered. I see the values contained in the array in the console. But I don't see the values displayed on the HTML page. The Controller: $scope.chosenFilm = []; //The array where…
Yacub Ali
  • 137
  • 2
  • 11
4
votes
2 answers

Angular 1.6.3 is not allowing a JSONP request that was allowed in 1.5.8

Angular 1.6.3 is not allowing a request that was allowed in 1.5.8 and I am getting this error: $sce:insecurl Processing of a Resource from Untrusted Source Blocked The full error is available here. I would like to upgrade my version of angular to…
Luke Schlangen
  • 3,722
  • 4
  • 34
  • 69
4
votes
1 answer

Encapsulating model in its own class for Angularjs app

I have 2 views. One is to list student in a table and the other is when you click on a student, it shows the details of the student. I have brought the student to it's own class in a separate file student.js. The thing is, student details don't get…
4
votes
1 answer

Referencing multiple API calls in one Service (Angular)

I am accessing an API via Angular $http requests to gather information for different football teams. If I were to be only accessing one team, this would be fine - I would create a Service that made the call, then reference the Service function in…
Paulos3000
  • 3,355
  • 10
  • 35
  • 68
4
votes
4 answers

$http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material

I'm using Angular Material md-autocomplete in my project. In that I'm getting the suggest listing from the Service Host via ajax call using $http service. Issue: $http issue - Values can't be returned before a promise is resolved in…
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
1 2
3
28 29