【发布时间】:2014-06-16 13:22:35
【问题描述】:
我正在用 Angular js 开发一个 SPA,并且没有使用服务器端语言,我只想在服务器上写一个日志 txt 文件。我使用下面的工厂代码进行了尝试,但是我通过此请求传递的数据需要服务器端代码来处理。如何在没有任何服务器端脚本(如 PHP、node js 等)的情况下直接使用 angular js $http 编写 txt 文件?
.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"
})
});
}
});
}]
)
【问题讨论】:
标签: angularjs angularjs-scope factory