Tag: 得到

节点express的bodyParser无法获取GET请求中的参数

我在客户端的ajax GET请求: $.ajax({ url: '/update', type: 'get', data: { "key": key, "value": value }, success: function (data, err) { } }) 然后在节点端,我想获取参数 var showParam = function (req, res) { if (req.body) { for (var key in req.body) { console.log(key + ": " + req.body[key]); } res.send({status:'ok',message:'data received'}); } else { console.log("nothing received"); res.send({status:'nok',message:'no Tweet received'}); […]

如何在express / node js发送错误http响应?

所以在login页面我发送证书从angular度来expression通过获取请求。我想要做的是,如果在数据库中发现,发送响应和angular度处理,否则,如果没有在数据库中find我想快递发送错误响应,并处理它angular度错误响应函数,但我的代码不工作。 angular度控制器: myapp.controller('therapist_login_controller', ['$scope' ,'$localStorage','$http', function ($scope, $localStorage,$http) { $scope.login=function(){ console.log($scope.username+$scope.password); var data={ userid:$scope.username, password:$scope.password }; console.log(data); $http.post('/api/therapist-login', data) .then( function(response){ // success callback console.log("posted successfully"); $scope.message="Login succesful"; }, function(response){ // failure callback,handle error here $scope.message="Invalid username or password" console.log("error"); } ); } }]); APP.js: app.post('/api/therapist-login',therapist_controller.login); 控制器: module.exports.login = function (req,res) { var userid=req.body.userid; var […]

Express.js:如何在req.param中创buildapp.get('/ i'..)?

我使用nodejs 0.8.21和3.1.0 我需要从像http://mysite.com/39i这样的http://mysite.com/39i读取userId 。 这意味着userId=39 。 怎么做? 谢谢。 样品: app.get('/:userId_i', function(req, res) { }); app.param('userId', function(req, res, next, id){ });

节点JS:自动select“http.get”与“https.get”

我有一个节点JS应用程序,需要下载一个文件,在运行时给定一个URL。 该URL可能是http://或https:// 。 我如何最好地迎合不同的协议? 目前我有: var http = require('http'); var https = require('https'); var protocol = (parsedUrl.protocol == 'https:' ? https : http); protocol.get(parsedUrl, function(res) { … }); …但感觉笨重。 谢谢!

NodeJS w / Express错误:无法GET /

这就是我所拥有的,文件名“default.htm”实际上是存在的,并在使用NodeJS执行readFile时加载。 var express = require('express'); var app = express(); app.use(express.static(__dirname + '/default.htm')); app.listen(process.env.PORT); 错误(在浏览器中): Cannot GET /