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

JSONP $http request to Dreamfactory returns server error

I am trying to access the dreamfactory data through $http request. To handle cross domain request, i have just added the JSON callback with the url. .factory('DonorService', ['$resource','$http', '$q', function($resource,$http,$q){ return{ …
Pamsix
  • 129
  • 1
  • 3
0
votes
1 answer

Converting curl POST to comply with the `angular-file-upload` format OR to achieve the same result using a custom Angular $http.post()

I am having a hard time to convert the following curl POST to comply with the angular-file-upload format curl -H "Content-Type: multipart/form-data" --form "jobSettings=$body" --form "upload=@$file" ${URL}?key=$key where: @file - an image file…
Nikolay Melnikov
  • 1,395
  • 1
  • 15
  • 25
0
votes
2 answers

$http.post data format in AngularJs

Problem Question: I am making a post call to my API but keep on getting 500 server error. After doing some debugging API is expecting data in different format API excepting -- user[email] -- json would be {user =>{email=>'test@test.com'} I am…
GeekOnGadgets
  • 941
  • 3
  • 14
  • 47
0
votes
1 answer

Creating a user-overridable config system in AngularJS

I'm working on a angularJS-based tool for building charts and am wanting to create a user-overridable config system — i.e., default values are loaded from one config file, which are then overridden if another config file exists. Here's what I have…
aendra
  • 5,286
  • 3
  • 38
  • 57
0
votes
2 answers

angular using jsonp - unexpected token

When i call "http://api.trademe.co.nz/v1/Search/Property/Residential.xml" using Jsonp I get an unexpected token error. I'm using the code below to call the…
Raju Kumar
  • 1,255
  • 3
  • 21
  • 39
0
votes
0 answers

AngularJs : $scope is in $apply phase ,still $http request is not sending immediately?

I am sending Http request . But its not immediately fire.And i already checked that its scope is in $apply phase. So any one have idea that Why this one is happening?? My service like: changeUserRole : function (groupId,roleObj) { var…
Shivali Patel
  • 884
  • 8
  • 12
0
votes
1 answer

Web api return null value

I have an Web Api controller for access data from server: public class ServicesController : ApiController { [AcceptVerbs("POST")] public IList LoadMetadata() { List itemsMenu = new…
Bogdan
  • 656
  • 15
  • 25
0
votes
1 answer

Http success not called

I'm trying a very simple thing in Angular: Call a json file via $http ... angular.module('testApp', []) .controller('TripCtrl', function ($scope, $http) { $http.get('http://localhost:8080/mydir/myfile.json'). success(function (data,…
mosquito87
  • 4,270
  • 11
  • 46
  • 77
0
votes
0 answers

Status Code 302 found on POST request using Angular, Revel and Go

I am using Revel + angular for my application. The index page is the login interface, and once you are successful, you should be directed to the dashboard.html page. The problem is once I have made a POST request, I get a GET request with my…
WarrenV
  • 230
  • 1
  • 2
  • 9
0
votes
1 answer

angular http get request through service needs refresh to show data

I found many similar questions but I couldn't apply the solutions to my problem. So in my angular app I am drawing nvd3 charts. I am doing a get request in the service and I can see from the network in my browser that I am ALWAYS getting the chart…
Nicolas Nicolas
  • 225
  • 2
  • 15
0
votes
1 answer

Cross-origin POST request not working even though it is allowed (GET works)

I have a weird problem. I am testing this using Angular.js 1.2.15. I want to send a POST request to a RESTful API backend on another domain (and I want to use $http directly, not $resource). var mapData = { 'some': 'keys', 'other':…
grssnbchr
  • 2,877
  • 7
  • 37
  • 71
0
votes
1 answer

AngularJS 'No 'Access-Control-Allow-Origin' header is present on the requested resource' error

I am using AngularJS 1.2.20. Whenever I use the $http service to access a zip file from a URL (different domain/server), it gives me an error as following: XMLHttpRequest cannot load http://localhost/ABC/updates.zip. No…
Temp O'rary
  • 5,366
  • 13
  • 49
  • 109
0
votes
1 answer

ASP.NET Multiple values sent using angular $http or $resource

If I submit a form using POST, the ASP.NET server can access each value by name. However, if I do it with javascript like: $http({ method: "POST", url: TDSV.ROOT_PATH + "/themes/" + data.id, params: { "xHttpMethodOverride": "PUT" }, …
AaronF
  • 2,841
  • 3
  • 22
  • 32
0
votes
2 answers

switching between api and flat json in angularjs

I think my stackoverflow search-fu is broken today, because it can't be that I'm the only one who's ever asked this. Cripes, I hope not, because I could really use some help figuring this out. Switching between data-sources is the big part, but…
kl02
  • 580
  • 6
  • 24
0
votes
1 answer

Ajax request from another domain using AngularJs

I'm using this book to learn AngularJS where I build this webapp with Angular, Node, Deployd. Now, my app stays at localhost:5000/app.html, 5000 is the port where node web server listen. I try to retrieve my data stored with deployd in this…
Ursus
  • 29,643
  • 3
  • 33
  • 50