AngularJS not detecting Access-Control-Allow-Origin header?
It’s a bug in chrome for local dev. Try other browser. Then it’ll work.
It’s a bug in chrome for local dev. Try other browser. Then it’ll work.
How to POST FormData Using the $http Service When using the FormData API to POST files and data, it is important to set the Content-Type header to undefined. var fd = new FormData() for (var i in $scope.files) { fd.append(“fileToUpload”, $scope.files[i]); } var config = {headers: {‘Content-Type’: undefined}}; var httpPromise = $http.post(url, fd, config); By … Read more
Promises are an abstraction over statements that allow us to express ourselves synchronously with asynchronous code. They represent a execution of a one time task. They also provide exception handling, just like normal code, you can return from a promise or you can throw. What you’d want in synchronous code is: try{ try{ var res … Read more
We ran into this problem because we had set up CORS according to best practice (e.g. http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api) AND ALSO had a custom header <add name=”Access-Control-Allow-Origin” value=”*”/> in web.config. Remove the web.config entry, and all is well. Contrary to @mww’s answer, we still have EnableCors() in the WebApiConfig.cs AND an EnableCorsAttribute on the controller. When we … Read more
The .success and .error methods are deprecated and have been removed from AngularJS 1.6. Use the standard .then method instead. $http.get(‘https://api.github.com/users’) .then(function (response) { var data = response.data; var status = response.status; var statusText = response.statusText; var headers = response.headers; var config = response.config; $scope.user = data; console.log(data); }); Deprecation Notice The $http legacy promise … Read more
How to Download Binary Files with AngularJS When downloading binary files, it is important to set the responseType: app.service(‘VerDocServices’,[‘$http’,function($http) { this.downloadFile = function(url, file, urlDir) { var config = { //SET responseType responseType: ‘blob’, params : { file : file, urlDir : urlDir } }; return $http.get(url, config) .then(function(response) { return response.data; }).catch(function(response) { console.log(“ERROR: … Read more
The problem was that .success and .error methods are not chainable because they ignore return values. This caused problems for people familiar with chaining and encouraged poor code from people unfamiliar with chaining. Witness all the examples on StackOverflow that use the deferred anti-pattern. To quote one of the AngularJS team: IMO .success and .error … Read more
I think you need to do is to transform your data from object not to JSON string, but to url params. From Ben Nadel’s blog. By default, the $http service will transform the outgoing request by serializing the data as JSON and then posting it with the content- type, “application/json”. When we want to post … Read more