|
其实吧,也就是没接收到 前台提交过来的值。 我想了想 后来百度了几小时后 发现是异步问题:
先贴个前端代码:- $.ajax({
- url : '/media/spresult',
- type : "POST",
- data : {
- // 'qksessionid': jwt
- 'applicantCn' : e.applicantCn //申请人名称(中文)
- ,'applicantEn' : e.applicantEn //申请人名称(英文)
- ,'intCls' : e.intCls //国际分类
- ,'regNo' : e.regNo //申请/注册号
- ,'tmName' : e.tmName //商标名称
- },
- // dataType : "json",
- success : function(ml){
- alert('成功了');
- console.log( e.applicantCn +'hhh' + e.applicantEn +'hhh'+e.intCls+'hhh'+e.regNo +'hhh'+e.tmName );
- },
- error : function(err){
- alert('err')
- layer.tips('服务器链接超时 请检查网络状况')
- }
- });
复制代码 可以看出,这是很常规的POST传值。但是后台 ,console.log(ctx.req.body) 显示 没值。 【我所用的是 multer 该情况下不能用 bodypaser, 有冲突】
我上述问题出在 异步上。
解决方法 就是加个 await
- // 点击搜索的接口
- router.post('/spresult', async(ctx,next) =>{
- // 接收失败 在这里 要异步获取
- await console.log(ctx.request.body);
- ctx.body ={
- "code": 0,
- "msg": "查询成功",
- "count": 56,
- }
- })
复制代码
|
|