我再页面的js文件中写了一个ajax提交表单。代码如下: ==============index.js $(".login_button").click(function(){ var userName = $(".loginUserName").val(); var password = $(".loginPassword").val().trim(); var user = { userName:userName, password:password }; console.log(‘name = ’ + userName); console.log(‘password = ’ + password); $.ajax({ type:‘post’, url:’/login’, data:user, success:loginSuccess, error:loginError }); });
===============app.js
app.use(’/’, routes); app.use(’/users’, users);
===========routes/index.js router.get(’/’, function(req, res, next) { res.render(‘index’, { loginFlag: ‘user’}); });
router.post(’/login’, function(req, res, next){ //登录 var user = { userName:req.body.user.userName, password:req.body.user.password } userDao.find(user, res, next); });
谁知道应该怎么修改才能让ajax有用?
目前使用结果就是:控制台输出 POST /login 500 1.438 ms - 1176