跟著教程用node寫(xiě)一個(gè)注冊(cè)的頁(yè)面,但報(bào)錯(cuò)了,教程是2015年的node4版本,我用的是node9,但是教程里的demo可以正常運(yùn)行我的就報(bào)錯(cuò)了,排錯(cuò)我是一點(diǎn)頭緒也沒(méi)有,表單的數(shù)據(jù)是能夠get出去的,表單提交頁(yè)的ajax<script>
???$("#regist").click(function?()?{
??????$.get("/doregist",{
??????????"name":$("#name").val(),
??????????"email":$("#email").val(),
??????????"password":$("#password").val()
??????},function?(result)?{
?????????if(result?==?"1"){
?????????????alert("注冊(cè)成功");
?????????}else?{
?????????????alert("注冊(cè)失敗");
?????????}
??????????????})
??????????});
</script>node 的JS代碼var?express?=?require('express');
var?app?=?express();
var?ejs?=?require('ejs');
var?formidable?=?require("formidable");
var?db?=?require('./model/db');
var?md5?=?require('./model/md5');
app.set('view?engine','ejs');
//靜態(tài)文件
app.use('/static',express.static('public'));
//路由
//首頁(yè)
app.get('/',function?(req,res,next)?{
????res.render('index')
});
//注冊(cè)頁(yè)
app.get('/register',function?(req,res,next)?{
????res.render('admin/register')
});
/*//登錄頁(yè)
app.get('/login',function?(req,res,next)?{
????res.render('admin/login')
});
//忘記密碼頁(yè)
app.get('/forget',function?(req,res,next)?{
????res.render('admin/forget')
});*/
/*//執(zhí)行注冊(cè)
app.post('/doregister',register.doRegister);*/
app.get('/doregist',function?(req,res,next)?{
????var?user?=?req.query.name;
????var?password?=?req.query.password;
????var?email?=?req.query.email;
????//加密
????????password?=?md5(password);
????//寫(xiě)入數(shù)據(jù)庫(kù)
????db.insertOne("users",{
????????"user"?:?user,
????????"password"?:?password,
????????"email"?:?email
????},function?(err,result)?{
????????if(err){
????????????res.send("-1");
????????????return;
????????}
????????res.send("1");
????})
});
/*
//用戶(hù)信息頁(yè)
app.get('/user',function?(req,res,next)?{
????res.render('admin/user')
});
*/
app.listen(3000);
node.js ajax GET提交失敗
村中長(zhǎng)相較好的男子
2018-01-02 17:28:58