angularjs-http

Angular's $http.post doesn't work, nor does its' $http… but jQuerys ajax does. Why?

北战南征 提交于 2019-12-11 05:20:49
问题 For some reason this: return jquery.ajax('my url', { crossDomain : true , data : JSON.stringify({"brand": self.current}) , type : 'POST' }).success(function(data){ scope.results = data; }); and/or this: curl -X POST -H "Content-Type: application/json" -d '{"brand":"target"}' myUrl work fine, but this: var req = { method: "POST" , url : "my url" , data : JSON.stringify({"brand": self.current}) }; return $http(req). success(function(data){ scope.results = data; }); fails miserably with "OPTIONS

AngularJS save image file sent from Web API 2

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:56:50
问题 I have been trying to follow different posts on downloading a file sent from my Web API. So far I can get the file to come, it will open the download window and it will save. However, I cannot open it so something must be wrong somewhere. Here is my AngularJS so far. return $http({ url: State.Endpoint + "/api/account/picture", method: "GET", responseType: 'arrayBuffer' }).then(function (data) { var octetStreamMime = 'application/octet-stream'; var success = false; var file = new Blob([data

AngularJS - Send $http GET request with associative array params

我们两清 提交于 2019-12-11 04:09:51
问题 with this code I am trying to send a $http.get request to my rest service: $http({ method: 'GET', url: '/api/item/all', params: { query: { userid: 7 }, fields: 'title' } }); I expected to access this URL: /api/item/all?query[userid]=7&fields=title but I am always getting a malformed url... So, how to proceed? Or even better: Is it possible to pass the full request url into the url-param of $http? 回答1: In a GET request, you should pass parameters as part of the query string. You can use the

angular component one-time binding from $http shows undefined

人走茶凉 提交于 2019-12-10 18:04:42
问题 I'm new to Angular. I'm trying to use components (1.6). In the parent, I have an $http.get that gets data from a service and then assigns the response to a $scope variable. That scope variable is passed to a child component using one-way binding < . In the JavaScript, if I alert the variable passed in, I get "undefined", however, the html template in the child does show the variable. It's like there is a race condition happening and I don't know how to tell it to wait until the data from the

Referencing multiple API calls in one Service (Angular)

我们两清 提交于 2019-12-10 15:49:42
问题 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 my controller. However, I want to do this on numerous teams, without having to create a separate Service module for each one. Service app.factory('APIService', ['$http', function($http) { return $http.get('http://API/team/1204?Authorization=xxxxx')

How can I make $httpBackend insensitive to the order of URL query parameters?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 12:30:01
问题 I am using the Angular.js $httpBackend to test some services that wrap $http calls (this is in ngMock, not ngMockE2E). It seems that things like expect and when are sensitive to the order of URL query parameters. E.g. if I do $httpBackend.when('POST','/apiCall?X=1&Y=2').respond(/* ... */) or $httpBackend.expectPOST('/apiCall?X=1&Y=2') , I get URL mismatches if I have Y=2&X=1 in the URL instead of X=1&Y=2 . I want to write my tests in such a way that the service being tested will be free to

Angularjs $http.get does not work

大憨熊 提交于 2019-12-10 07:41:27
问题 My purpose is to consume a REST web service in AngularJS and I am making some trials right now. Below code is not working and throwing following exception. Can you help me identifty the problem? Thanks in advance. function getUsersFromLocal($scope,$http) { $http.get('http://localhost:8080/people'). success(function(data) { $scope.data = data; }); return data; } Error is: TypeError: Cannot read property 'get' of undefined at getUsersFromLocal. The service is accessible and I tested it through

Undefined $http data when resolved with `.then` method

隐身守侯 提交于 2019-12-08 07:31:29
问题 I used the console log which returned the array of data fetched from the server, but when I call the scope on the html I get an undefined error on the console. app.service('blogpostservice', ['$http', function ($http) { this.getMoreData = function (pagecount) { return $http.get('/api/posts/' + pagecount); } }]); app.controller('MainController', ['$scope', 'blogpostservice', function ($scope, blogpostservice) { $scope.pagec = 1; this.getMoreData = function () { blogpostservice.getMoreData(

Is it possible to specify parameter order with Angular's $http service?

混江龙づ霸主 提交于 2019-12-07 17:18:36
问题 In my Angular app, I have a service that utilizes $http to retrieve data from a server. The server endpoint uses HMAC authentication and expects the query string parameters to be in a specific order on the URL. Angular sorts the $http parameters when it builds the URL, so it doesn't seem possible to specify a custom parameter order. Here's an example: this.apiCall = function() { return $http({ method: 'GET', url: 'http://example.com/url/v1/endpoint', params: { 'c': 'cdata', 'a': 'adata', 'b':

With AngularJS, I don't want to set the global $http.defaults.headers.common. Can I send my custom header with each $resource call?

若如初见. 提交于 2019-12-07 10:10:43
问题 I'm calling a back-end server that I cannot control. Currently it's using jQuery ajax like this: return $.ajax({ type: "POST", url: "/api/cases/store", contentType: "application/json", data: JSON.stringify(parameters), headers: { "Authorization": cred } : {} }) // ... etc. I want to convert it to use the $resource service, and got it working doing this $http.defaults.headers.common['Authorization'] = cred; return $resource('/api/cases/store').save(); The only problem is that I'm having to set