angularjs-http

Using success/error/finally/catch with Promises in AngularJS

蓝咒 提交于 2019-11-26 18:14:35
I'm using $http in AngularJs, and I'm not sure on how to use the returned promise and to handle errors. I have this code: $http .get(url) .success(function(data) { // Handle data }) .error(function(data, status) { // Handle HTTP error }) .finally(function() { // Execute logic independent of success/error }) .catch(function(error) { // Catch and handle exceptions from success/error/finally functions }); Is this a good way to do it, or is there an easier way? Promises are an abstraction over statements that allow us to express ourselves synchronously with asynchronous code. They represent a

AngularJS Upload Multiple Files with FormData API

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:01:18
I need to upload image and video files to the server in an Angular application using Laravel 5.1 as the back end. All Ajax requests need to go to the Laravel controller first, and we have the code there for how the file gets handled when it gets there. We have previously done normal HTML forms to submit file uploads to the controller, but in this case we need to avoid the page refresh of a form, so I am attempting this in Ajax through Angular. What information do I need to send to the Laravel controller with Ajax that was being sent to the controller via an HTML form previously? This is the

AngularJS Uploading An Image With ng-upload

一世执手 提交于 2019-11-26 15:20:45
问题 I am trying to upload a file in AngularJS using ng-upload but I am running into issues. My html looks like this: <div class="create-article" ng-controller="PostCreateCtrl"> <form ng-upload method="post" enctype="multipart/form-data" action="/write" > <fieldset> <label>Category</label> <select name="category_id" class=""> <option value="0">Select A Category</option> <?php foreach($categories as $category): ?> <option value="<?= $category -> category_id; ?>"><?= $category -> category_name; ?><

Error with $http.get in angularJS — Success not a Function [duplicate]

心已入冬 提交于 2019-11-26 14:42:01
This question already has an answer here: Why are AngularJS $http success/error methods deprecated? Removed from v1.6? 2 answers Getting this error: angular.min.js:122 TypeError: $http.get(...).success is not a function at getUserInfo (app.js:7) at new (app.js:12) at Object.invoke (angular.min.js:43) at Q.instance (angular.min.js:93) at p (angular.min.js:68) at g (angular.min.js:60) at g (angular.min.js:61) at g (angular.min.js:61) at angular.min.js:60 at angular.min.js:21 Here is my code: var gitHub = angular.module('gitHub', []); gitHub.controller('mainController', ['$scope', '$http',

Angular Js - set token on header default

风格不统一 提交于 2019-11-26 09:43:23
问题 Im trying to add a header with my access token to each API call. It works well for all the GET requests, but as soon as I try to make a POST the header isn\'t added. Here is how I add the token: app.factory(\'api\', function ($http, $cookies) { return { init: function (token) { $http.defaults.headers.common[\'Token\'] = token || $cookies.loginTokenCookie; } }; }); Which gets called from here: app.run(function ($cookies, $http, $location, $rootScope,api) { $rootScope.location = $location; api

AngularJS not detecting Access-Control-Allow-Origin header?

限于喜欢 提交于 2019-11-26 08:21:43
问题 I am running an angular app on a local virtualhost (http://foo.app:8000). It is making a request to another local VirtualHost (http://bar.app:8000) using $http.post . $http.post(\'http://bar.app:8000/mobile/reply\', reply, {withCredentials: true}); In the Network tab of Chrome Developer Tools I of course see the OPTIONS request, and the response includes the header: Access-Control-Allow-Origin: http://foo.app:8000 However, the POST request is cancelled with the following error: No \'Access

Using success/error/finally/catch with Promises in AngularJS

左心房为你撑大大i 提交于 2019-11-26 06:15:28
问题 I\'m using $http in AngularJs, and I\'m not sure on how to use the returned promise and to handle errors. I have this code: $http .get(url) .success(function(data) { // Handle data }) .error(function(data, status) { // Handle HTTP error }) .finally(function() { // Execute logic independent of success/error }) .catch(function(error) { // Catch and handle exceptions from success/error/finally functions }); Is this a good way to do it, or is there an easier way? 回答1: Promises are an abstraction

Error with $http.get in angularJS — Success not a Function [duplicate]

人走茶凉 提交于 2019-11-26 03:30:33
问题 This question already has answers here : Why are AngularJS $http success/error methods deprecated? Removed from v1.6? (2 answers) Closed 5 months ago . Getting this error: angular.min.js:122 TypeError: $http.get(...).success is not a function at getUserInfo (app.js:7) at new (app.js:12) at Object.invoke (angular.min.js:43) at Q.instance (angular.min.js:93) at p (angular.min.js:68) at g (angular.min.js:60) at g (angular.min.js:61) at g (angular.min.js:61) at angular.min.js:60 at angular.min.js

The &#39;Access-Control-Allow-Origin&#39; header contains multiple values

末鹿安然 提交于 2019-11-26 03:10:37
问题 I\'m using AngularJS $http on the client side to access an endpoint of a ASP.NET Web API application on the server side. As the client is hosted on a different domain as the server, I need CORS. It works for $http.post(url, data). But as soon as I authenticate the user and make a request via $http.get(url), I get the message The \'Access-Control-Allow-Origin\' header contains multiple values \'http://127.0.0.1:9000, http://127.0.0.1:9000\', but only one is allowed. Origin \'http://127.0.0.1

How to enable CORS in AngularJs

99封情书 提交于 2019-11-25 22:18:03
问题 I have created a demo using JavaScript for Flickr photo search API. Now I am converting it to the AngularJs. I have searched on internet and found below configuration. Configuration: myApp.config(function($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common[\'X-Requested-With\']; }); Service: myApp.service(\'dataService\', function($http) { delete $http.defaults.headers.common[\'X-Requested-With\']; this.flickrPhotoSearch = function() {