码迷,mamicode.com
首页 > 其他好文 > 详细

express post 数据

时间:2017-04-04 21:39:59      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:post   exp   undefined   use   port   fine   color   title   timeout   

 

 

export function saveEssay(essay){
    $.ajax({  
      url: ‘http://127.0.0.1:1724/saveessay‘,  
      type: ‘post‘,
      data:essay,  
      dataType: ‘json‘,  
      timeout: 1000,  
      cache: false,  
      success:function(data){
        // resolve(data)
      },
      error:function(){
        // reject()
      }
    }) 
  }

 

app.post(‘/saveessay‘, function(req, res){
    console.log(req.body)
})

 

req.body收到的是undefined

var bodyParser = require(‘body-parser‘);
app.use(bodyParser());

 

解析body中的内容

 

成功

pic20

{ title: ‘1‘, content: ‘‘, id: ‘2‘ }

 

 

pic 21

保存文章

 

pic22

数据库保存成功

 

express post 数据

标签:post   exp   undefined   use   port   fine   color   title   timeout   

原文地址:http://www.cnblogs.com/heinz-lxy/p/6666419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!