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

Spring Controller 400 (Bad Request)

I am getting bad request issue from spring controller. (Reason : The request sent by the client was syntactically incorrect.) Below is my rest call : Requested payload: categoty: "Game" itemDescription: "adas" itemDiscount: 1 itemName:…
user3440629
  • 198
  • 9
0
votes
2 answers

Force AngularJS $http.post to return JSON

Coming from jQuery, setting the content-type to application/json would give me a json object instead of an xml-formatted string. How can I achieve the same using AngularJS $http.post? Tried doing $http({ method: "post", url: "url", …
Sharon Dorot
  • 542
  • 1
  • 4
  • 15
0
votes
1 answer

Make get calls in angular js after a small time of key up event

I am beginner in angular js, In my application I am using a web api that provides, place when we enter pincode. I am calling a function in my controller on keyup event of textfield, but it throws some error, and some time not makes the get call in…
droidev
  • 7,352
  • 11
  • 62
  • 94
0
votes
1 answer

Get request to Json does it need jsonp

I am using Angular v1.2.15 to GET a URL to retrieve JSON results. I need to send a custom AUTHENTICATION Header with the request. the url will send back Json. So far I can only get both $resource and $http to even send the request if I use JSONP…
0
votes
0 answers

Modify or access angular interceptors after config phase

Is it possible to access / modify $http interceptors after the config phase? I'm debugging an app that only breaks in production due to being deployed on a different server, so unfortunately I can't change the interceptor code locally and figure out…
0
votes
4 answers

AngularJS HTTP Resource - Response Function Undefined

I'm using an Angular HTTP Resource to get some data from an API. The method on the API is actually a PUT, but returns an array of data. (Note, it's not my API) It performs the HTTP Call perfectly and I can see in the Network on Google Developer…
Jeremy Wagner
  • 485
  • 4
  • 9
  • 19
0
votes
1 answer

AngularJS: $http service GET to php server: Request Method:OPTIONS, Status Code: 405 Method Not Allowed

I'm struggling with this issue since many hours... :-( My grunt-served angular app issues an $http GET request to a simple PHP service on the same host (apache), to get a list of persons. The result I get is an OPTIONS request (???), which gets a…
MarcoS
  • 17,323
  • 24
  • 96
  • 174
0
votes
2 answers

IE9 receives JSON response as a line of CharCodes in Restangular

In my application we use Restangular and $http to communicate with server API. First request (the one /BasicInfo.json on the picture) is done using Restangular for retrieving initial information, like user name, and also Number pointer to part of…
shershen
  • 9,875
  • 11
  • 39
  • 60
0
votes
1 answer

Angular + httpService: POST & DELETE results?

I've got an angular services which should do all the http stuff required to let my controllers talk with my API. export interface IDummyEntityApiService { getAllDummies() : ng.IPromise>; } class DummyEntityApiService…
xvdiff
  • 2,179
  • 2
  • 24
  • 47
0
votes
1 answer

Capturing cookies from responses to Angular's $http request

In my Angular app, I am logging in to the app's backend through an REST API call using $http. When I log in to the app, the backend returns a Cookie that preserves the logged in status of the user. I want to store this cookie info somewhere so I can…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
0
votes
1 answer

angular $http vs jquery $ajax - dataType for angular?

How can I set the ajax return data type in angular? For instance I can set it easily in jquery if I want the response data to be html. jquery, $.ajax({ url: "script.php", type: "GET", dataType: "html" }); angular, $http({ method: "get", …
Run
  • 54,938
  • 169
  • 450
  • 748
0
votes
3 answers

How to click to load a html form into a target in angular?

How can I click to load a html form into a target in angular without using jquery? My working script so far but I am stuck on