Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从前端表单发出post请求时出现内部服务器错误500_Node.js_Mongodb_Forms_Post_Internal Server Error - Fatal编程技术网

Node.js 从前端表单发出post请求时出现内部服务器错误500

Node.js 从前端表单发出post请求时出现内部服务器错误500,node.js,mongodb,forms,post,internal-server-error,Node.js,Mongodb,Forms,Post,Internal Server Error,当我通过在前端填写表格发出post请求时,我收到内部服务器错误500。请有人帮忙。当我从邮递员那里发出请求时,同样的错误也会发生。如何解决这个问题 学生模型后端代码和前端代码 const mongoose=require('mongoose'); const Schema=mongoose.Schema const studentSchema=新模式({ 学生姓名:{ 类型:字符串, 必填项:true }, sid:{ 类型:字符串, 独一无二:没错, 必填项:true }, 美孚利诺:{ 类型

当我通过在前端填写表格发出post请求时,我收到内部服务器错误500。请有人帮忙。当我从邮递员那里发出请求时,同样的错误也会发生。如何解决这个问题

学生模型后端代码和前端代码

const mongoose=require('mongoose');
const Schema=mongoose.Schema
const studentSchema=新模式({
学生姓名:{
类型:字符串,
必填项:true
},
sid:{
类型:字符串,
独一无二:没错,
必填项:true
},
美孚利诺:{
类型:字符串,
独一无二:没错,
必填项:true
},
性别:{
类型:字符串,
必填项:true
},
电邮:{
类型:字符串,
必填项:true
},
分支机构:{
类型:字符串,
必填项:true
},
国籍:{
类型:字符串,
要求:正确,
},
地址:{
类型:字符串,
要求:正确,
},
父名:{
类型:字符串,
必填项:true
},
母亲姓名:{
类型:字符串,
必填项:true
},
fatherMobile:{
类型:字符串,
必填项:true
},
出生日期:{
类型:字符串,
必填项:true
},
照片:{
类型:字符串,
必填项:true
},
房间号:{
类型:字符串,
必填项:true
},
宿舍:{
类型:mongoose.Schema.Types.ObjectId,
参考:旅馆
},
});
const Students=mongoose.model(“学生”,studentSchema);
module.exports=学生
后端代码

studentRouter.route(“/”)
.options(cors.corsWithOptions,(req,res)=>{res.sendStatus(200);})
.get(cors.cors,authenticate.verifyUser,(req,res,next)=>{
控制台日志(请求用户宿舍)
查找({hostel:req.user.hostel})
.populate('旅馆')
.然后((学生)=>{
res.statusCode=200;
res.setHeader('Content-Type','application/json')
res.json(学生);
},err=>next(err))
.catch(err=>next(err))
})
.put(cors.corsWithOptions,authenticate.verifyUser,authenticate.verifyAdmin,(req,res,next)=>{
res.end('Put请求在/students端点上无效')
})
.post(cors.corsWithOptions,authenticate.verifyUser,authenticate.verifyAdmin,(req,res,next)=>{
req.body.hostel=req.user.hostel;
学生。创建(要求正文)
.然后((学生)=>{
Students.findById(student.\u id)
.populate('旅馆')
.然后((学生)=>{
res.statusCode=200;
res.setHeader('Content-Type','application/json');
res.json(学生)
},err=>next(err))
},(err)=>next(err))
.catch((错误)=>next(错误))
})
前端代码

export const poststudior=(学生)=>(调度)=>{
const newStudent={
studentName:student.name,
希德:学生证,
mobileNo:student.mobile,
性别:学生,性别,
电子邮件:student.email,
分支机构:学生分支机构,
国籍:学生国籍,
地址:student.address,
父亲姓名:学生。父亲,
母亲姓名:学生,母亲,
父亲:学生,Fnum,
多布:学生,多布,
照片:学生照片
}
log('Student:',newStudent);
const bearer='bearer'+localStorage.getItem('token');
返回获取(baseUrl+“学生”{
方法:“POST”,
标题:{
“内容类型”:“应用程序/json”,
“授权”:持有人
},
正文:JSON.stringify(newStudent),
凭据:“相同来源”
})
。然后(响应=>{
控制台日志(响应);
if(response.ok){
返回响应;
}
否则{
var error=新错误('error'+response.status+':'+response.statusText);
error.response=响应;
投掷误差;
}
},
错误=>{
var errmess=新错误(Error.message);
乱扔垃圾;
})
.then(response=>response.json())
。然后(响应=>dispatch(addStudent(响应)))
.catch(错误=>{console.log('Post students',error.message));
警报('无法添加您的学生\n错误:'+error.message);})
}