Search Posts

Category: http

How to pass an object param with $http POST and access in Nodejs service

I have created a POST request where i am sending a param to server and in the server side i am getting the error is like the data not found. Client js var postData= JSON.stringify({name:”Alex”,age:”34″}); var deferred = $q.defer(); $ + ‘/users’, postData) .success(function (response) { deferred.resolve(response) }).error(function (error) { deferred.reject(‘Failed to connect’); }); return deferred.promise; } Serverjs (Nodejs)‘/api/users’, function (req, res) { var user = req.body.postData; // user is not getting in server […]

How to avoid catching the HTTP OPTIONS request in the express.js auth middleware

Okay I have a backend API built in express.js that responds to a SPA built in AngularJS. I am using token authentication to verify the access of clients to fetch certain resources. The way I check on wether the incoming request from the front-end has an Authorization header containing the Bearer token or not is in an authentication middleware I made myself in express.js. The problem is that AngularJS sends a preflight OPTIONS reuqest before […]

Angularjs get pre-flight (OPTIONS) request result

I have an angularjs application that make a http GET request to my backend using $http service. I would like to have the status code of the pre-flight test request to customize the errors management. Is it possible to do that? At the moment when the OPTIONS fail (for example with a 400) the status code of the GET is -1. Thanks in advance Source: AngularJS

2 $http get function

Given 2 JSON url, how do I make sure the code has finished retrieving the data from a.json, then only start retrieving the data from b.json, then only run init function? var aUrl = “a.json”; var bUrl = “b.json”; My attempt: var app = angular.module(‘calendarApp’, []); app.controller(‘ctrl’, function($scope, $http) { $http.get(aUrl).success(function(data) { }); $http.get(bUrl).success(function(data) { init()} ); var init = function(){} Source: AngularJS

Data must be valid JSON angularjs service passing data issue

When I’m sending to API data like this: this.login = function (loginInfo) { return $http({ url: ‘http://localhost/igt/api/public/signin’, headers: { ‘Content-Type’: ‘application/json’ }, method: ‘POST’, data: { user: { name: “nick”, password: “password” } } }) It is working correctly it send me back data: password is wrong, and eveything is correct. When I’m sending to API data like this: this.login = function (loginInfo) { return $http({ url: ‘http://localhost/igt/api/public/signin’, headers: { ‘Content-Type’: ‘application/json’ }, method: ‘POST’, […]

Different response in postman and in angularjs service

So when I’m calling endpoint from postman I got response like this: And when I’m calling same request from my angularjs service which is: this.login = function (loginInfo) { return $http({ url: ‘http://localhost/igt/api/public/signin’, headers: { ‘Content-Type’: ‘Application/json’ }, method: ‘POST’, user: { name: “nick”, password: “password” } }) .then(function(response) { console.log(response); }, function (err) { console.log(“err:”); console.log(err); }); }; I’ve got output in console like this: which is this: { “data”: null, “status”: 400, “config”: […]

How to make client not disconnect when server response takes a long time

I have a Java backend with REST-API and an Angularjs frontend. Users can use the frontend to request information from the backend. When this happens, the backend generates a file on the fly and sends it to the frontend. So far so good. The problem occurs when users request large amounts of information. This makes generating the file take so long that the frontend times out and aborts the connection. Is there a way to […]

AngularJS $http DELETE request does not send the Authorization Header in IE

We do a http DELETE to a secured resource with AngularJS’s $http, where we also send some authorization info: Authorization: Bearer eyJhbGciOiJSUzI1Ni… This works in Chrome and Firefox but not in IE.. In IE Developer’s Network Tab we see a 403 HTTP error (Forbidden), and we do not see the Authorization header. I have also tried to run this document.execCommand(‘ClearAuthenticationCache’); and this document.execCommand(‘ClearAuthenticationCache’, false); in app.js as well as just before the http call, but […]

LocalStorage + AngularJS + $http Como retornar dados armazenados em array de objetos

Primeiramente, boa noite. Estou armazenando informações dentro de um localStorage através de um array de objetos. Preciso cadastrar cartões, e cada cartão cadastrado um conjunto de informações é armazenado no navegador como cvv, bandeira, nome, etc. É possível visualizar mais facilmente através da print abaixo. Minha necessidade é a seguinte: Quando eu for fazer um pagamento, devo selecionar um dos cartões armazenados e então, enviar para o destino através do método POST. Mas meu problema […]

Next Page »