user3725294
user3725294

Reputation: 105

File handling for log with angular js $http

I am developing a SPA in angular js and there is no server side language used, I just want to write a log txt file at server. I tried it using below factory code, but the data which i passed through this request needs a server side code to handle. How can i write a txt file directly with angular js $http without any server side script like PHP, node js etc?

.factory( "applicationLoggingService", ["$log","$window",function($log, $window){

                return({
                    error: function(message){
                        // preserve default behaviour
                        $log.error.apply($log, arguments);
                        // send server side
                        $http({
                            url: "log/logger.txt",
                            method: "PUT",
                            params: angular.toJson({
                                url: $window.location.href,
                                message: message,
                                type: "error"
                            })
                        });
                    },
                    debug: function(message){
                        $log.log.apply($log, arguments);
                        $http({
                            url: "log/debug_logger.txt",
                            method: "PUT",
                            params: angular.toJson({
                                url: $window.location.href,
                                message: message,
                                type: "debug"
                            })
                        });
                    }
                });
            }]
        )

Upvotes: 1

Views: 2820

Answers (1)

GonchuB
GonchuB

Reputation: 705

As far as I know, you won't be able to do such thing without writing server side code. Your back end needs to handle the PUT log/logger.txt. I believe the only thing you could do without writing server code is write to a local file (a file in the client's computer).

Where's your app hosted? Why is writing server side code such an issue?

Upvotes: 1

Related Questions