Questions tagged [angular-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.

970 questions
0
votes
2 answers

Angular JS - can't receive any response using $http.post

I'm trying to get a response from a web service using Angular JS, which I can perfectly reach via my shell using a simple curl command: curl --header "Content-type: application/json" --request POST --data '{"username": "name", "password":…
domokun
  • 3,013
  • 3
  • 29
  • 55
0
votes
4 answers

Angularjs $http not sending form data to the server

The below code works if I use jquery ajax but $http of Angular doesn't send any data to the server using the code below: myapp.factory('startCampFactory',function($http,$q,$rootScope){ return { startNewCampaign : function(){ var e =…
rohit
  • 83
  • 1
  • 2
  • 14
0
votes
2 answers

AngularJs: How to cache $http properly?

I've enabled cache in my $http request and now the callback for success only runs the first time. I'm wondering if this is expected or there's something I need to know about caching $http ? This is what I've been trying: $http.get('/foo/bar', {…
punkbit
  • 7,347
  • 10
  • 55
  • 89
0
votes
0 answers

Async POST request inside angular.forEach

Making an Async post request inside .forEach is causing me a lot of problems. With or without the use of $resource I will get data lose. Or maybe the server just can't get all the requests processed at the same time, I don't really know. Here is the…
sebastiannm
  • 565
  • 1
  • 5
  • 14
0
votes
0 answers

Testing $http calls in Angular 1.1.5

I'm running into trouble trying to mock my $http calls in Angular. When calling $httpBackend.flush() I'm getting the error: Error: No pending request to flush ! I've read up on many other posts of similar issues on here, but I still can't seem to…
jbenowitz
  • 1,795
  • 6
  • 26
  • 39
0
votes
1 answer

second angular $http request doesn't reach its destination

I'm setting up a oauth-like flow, where making an actual request is postponed until some preliminary negotiation has completed. The preliminary negotiation works, but when I try to make the request for the desired resource, I get the following…
lowerkey
  • 8,105
  • 17
  • 68
  • 102
0
votes
1 answer

Angular.js canceling $http requests inside bind() event

According to this https://github.com/angular/angular.js/issues/1159 this should work, shouldn't it? el.bind('keyup', function() { var canceler = $q.defer(); $http.post('/api', data, {timeout: canceler.promise}).success(success); …
fxck
  • 4,898
  • 8
  • 56
  • 94
-1
votes
0 answers

How to resolved ERROR Error: Uncaught (in promise): Error? When I run prerender command in Angular Terminal then I got this issue

When I processed the PRERENDER process in console for generating static pages for firebase website deployment that time my subpages' SEO meta tags and page contents not generate the data as per page contents. but all my page data is still in the…
-1
votes
0 answers

CORS error "No 'Access-Control-Allow-Origin' header is present on the requested resource" when running Angular locally

I have a working MEAN stack in AWS Lightsail and I've refractor the API for Serverless Lambda. I'm getting the "no 'Access-control-allow-origin'" error when I run from Angular locally. (e.g. with 'ng serve' to my Serverless API. I've tried to…
-1
votes
1 answer

How to use *application/x-www-form-urlencoded* in angular 8 HTTP request with codigniter API

Here we will tell you the solution for call HTTP client POST request in angular 8
-1
votes
1 answer

Angular try to GET after POST

Can't understand the http module from angular, all works good, but when i insert new data and do the new request, it is in different order, the request get is executed before the POST The init event (it works) ngOnInit() { this.refresh(); } …
grijalvaromero
  • 589
  • 1
  • 6
  • 20
-1
votes
1 answer

Angular 4 http service call fails to call the spring rest service method

I am beginner to Angular 4 as well as spring boot rest. I made a simple app which has Angular 4 as front end and Spring Rest as API. I am trying to call Spring Rest controller method (Post) from Angular http request. Following is the Angular 4…
-1
votes
1 answer

Angular refresh token interceptor

I'm trying to make an interceptor to refresh the user token if there is an authentication error. I'm asking this here because even with some tutorials and other questions I can't make mine works. Here is my intercept function : public intercept(req:…
-1
votes
1 answer

How to make a normal post request in angular 4

My question is very simple... I need to make a regular post request in angular 4 app, like as html form post, that is that replace the window location..because if I do it using HttpClient, this makes an ajax POST... My question is... How to make a…
AlejoDev
  • 4,345
  • 9
  • 36
  • 67
-1
votes
1 answer

wait till the request completes in angular

In my angular application, I have one parent component i.e. Dashboard Component having 2 Sub Components i.e. Analytics Component & Stats Component. My dashboard.component.html looks like this
Ganesh
  • 5,808
  • 2
  • 21
  • 41