title: jquery ajax post to express server get undefined data
body: <p>im trying to get a form to submit some data to my express app.js without the page reloading. I thought i had the correct code but when it comes to getting the code from the ajax call to the server i get a undefined data variable. </p>
  
  <p>app.js: (removed irrelevant lines)</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  
  var index = require('./routes/index');
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  // uncomment after placing your favicon in /public
  app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.get('/web_text.json',function(req, res, next){
      res.sendFile(__dirname + '/web_text.json');
  });
  
  app.post('/sendEmail', function (req, res) {
  
      console.log(req.body.data);
  
  });
  
  app.use('/', index);
  
  module.exports = app;
  </code></pre>
  
  <p>jquery function that makes ajax call:</p>
  
  <pre><code>$('#reserve form').on('submit', function(){
  
      event.preventDefault();
      var data = {
  
          name: $('#name').val()
      };
      console.log(data);
      $.ajax({
          url: 'http://localhost:3000/sendEmail',
          data: data,
          method: 'POST'
      }).then(function (response) {
        // Do stuff with the response, like add it to the page dynamically.
        $('body').append(response);
      }).catch(function (err){
  
          console.error(err);
      });
  });
  </code></pre>
  
  <p>note the console.log()s in my /sendEmail app.post function and the one in the jquery function. the jquery one logs the correct data while the app.post one logs a undefined variable... what am i doing wrong? thanks in advance</p>