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
-1
votes
1 answer

Angularjs $http post promise

I try to use the promise respond from a $http.post, to get back the new ID of the record as integer and use it for the next $http.post. I used How do I return the response from an asynchronous call? for help but it still don´t work. var…
74ck
  • 65
  • 2
  • 9
-1
votes
2 answers

In AngularJS, $http doesn't change my select option tag data

I have an issue in AngularJS on using $http to fetch data from server. Here is my HTML Here is my AngularJS Script angular.module("myApp").controller("myCtrl",…
-1
votes
1 answer

Scope of $http callback in ES6

I'm trying to write a quick test that uses ES6 and Angular to call an API - but I can't quite work out how to scope the injected values into the callbacks - in all cases they seem to be completely isolated. Any suggestions?? class Test…
Silver
  • 4,911
  • 3
  • 15
  • 16
-1
votes
2 answers

Property on $scope set inside of $http.success() is undefined outside of $http.success(). Why?

I am following an AngularJS tutorial that uses $resource to retrieve JSON data from an API call. For the purpose of understanding, I tried to replace the $resource code with $http code and I encountered a scope problem. Logging…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
-1
votes
2 answers

POST 404 Not found.. Angular js

here i'm sending data through $http.post to data/user.php app.factory('loginService',function($http){ return{ login:function(data,scope){ var $promise=$http.post('data/user.php',data); //send data to user.php …
-3
votes
1 answer

How to display response data ($http) from server in AngularJS

How to display reponse data (get) from server in AngularJS in my code I need to alert $scope.orders inside that controller but it willll not show.. function OrderController($scope,$http) { var orderPromise = $http.get("../api/order"); …
symon kt1
  • 45
  • 2
  • 11
1 2 3
28
29