Search Posts

Category: http

AngularJS: $http fire and forget (no $apply)

My custom exception-Handler is sending a logging-event over $http whenever an exception occurs (similar to the example in the docs https://docs.angularjs.org/api/ng/service/$exceptionHandler ). angular. module(‘exceptionOverwrite’, []). factory(‘$exceptionHandler’, [‘$log’, ‘$http’, function($log, $http) { return function myExceptionHandler(exception, cause) { $http.post(‘myUrl.com/logErrors’, cause); $log.warn(exception, cause); }; }]); This works as desired… Except when it doesn’t: The Problem: Angular uses databinding to bind logic from controllers to the view. However this seems to cause infinity-loops in this constellation:. Whenever an Error […]

How to handle HTTP error in the client side?

What is the best way to handle HTTP errors (404, 503, etc.) when submitting a crucial data on the server? Possible solutions I came up with: having the data stored in the session for later submission (data is lost if session expired) have the data downloaded by the user and manually submit it again is it possible to store the data as cookie? Source: AngularJS

AngularJS callback error and is not a function

I have an error in line callback(response.data) telling that callback is not a function. Well, I am new to this and I am trying to figure out how to fix this issue but I am having a tough time. Any idea is appreciated. Thanks app.service(‘NotificationPollService’, function ($q, $http, $timeout) { var notification = {}; notification.poller = function (callback, error) { return $http.get(‘api/sample.php’).then(function (response) { if (typeof response.data === ‘object’) { callback(response.data); } else { error(response.data); […]

Add an exception do defaults headers in angularJS

Hello I want to use external API to gather all the current currency rate. My front is based on token and I am storing token in localForage which is nothing but async localStorage. //this execute after every page refresh $localForage.getItem(‘authorization’) .then(function(authData) { if(authData) { $scope.authentication.isAuth = true; $http.defaults.headers.common.Authorization = ‘Bearer ‘ + authData.token; //set authentication variable to true and add token to every request after page refresh } }, function(){ console.log(“error with getting authorization localForage […]

AngularJS – How to send an audio file through $http post?

So I’ve been trying to send an audio file through an $http service using FormData, and so far what I have tried to send the file hasn’t worked yet. This is how the service looks like: songs_services.add_new_song = function(new_song_name, new_song_artist, song) { var fd = new FormData(); fd.append(“new_song_name”, new_song_name); fd.append(“new_song_artist”, new_song_artist); fd.append(“song”, song); console.log(fd.get(“new_song_name”)); console.log(fd.get(“new_song_artist”)); console.log(fd.get(“song”)); return $http.post(BACKEND_PREFIX + “add_new_song”, fd, { transformRequest: angular.identity, headers: {‘Content-Type’: undefined} }).then(function() { }, function() { }); }; I […]

$http.get is not giving response

I’m new to node and angular script. I’m having a function readDetails within my service which gives a GET request. this.readDetails = function() { return $http({ method: ‘GET’, url: ‘/getDetails’ }).then(function(data) { return data; }); } Given below is my server side code. app.get(‘/getDetails’, function(request, response) { fs.readFile(‘details.json’, ‘utf8′, function(err, data) { if (err) throw err; var obj = JSON.parse(data); response.send(obj); response.end(); }) }) I don’t get the response from the server. I do not […]

AngularJS – ‘Data must be a valid JSON object’ error when loading via $http get

I’m trying to extract data for a list of employees from a json file using a $http.get request in my angular app, but the console is showing the following error: Error: [$http:baddata] Data must be a valid JSON object. Received: “{…… Not sure what is wrong, but I’ve not worked with http requests to get json files much before, and I think my json looks fine. – JSON: { ’employees’: [ { id: ‘21101994’, icon: […]

Failed to connect socket using https in nodejs

While developing a chat application using nodejs,angular i am trying to connect with socket with the help of namespace using http , it was perfectly working.While i am running the same application with https, it was not connecting to socket code. server require(‘./libs/socketioCode.js’).sockets(https); var options = { key: fs.readFileSync(‘privkey.pem’), cert: fs.readFileSync(‘cert.pem’) }; var server = http.createServer(app).listen(3000); var server1 = https.createServer(options, app).listen(3443); var io = require(‘socket.io’).listen(server1); socket module.exports.sockets = function(https){ io = socketio.listen(https); I tried this […]

AngularJS $http request issue in HTTP and HTTPS

I have a problem in my angularjs $http request. When I send request to the API it was blocked by the browser like: ERROR IN FIREFOX : Blocked loading mixed active content “http://www.example.com/rest/default/V1/integration/admin/token/” ERROR IN CHROME: Mixed Content: The page at ‘https://www.example.com/load.shtml#/register/pos/docs/2323232221555/new‘ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘http://www.example.com/rest/default/V1/integration/admin/token/‘. This request has been blocked; the content must be served over HTTPS. How can I fixed this problem? Any idea is accepted. […]

Next Page »