title: JQuery Ajax post request with node.js and express
body: <p>I was trying to make AJAX post request with JQuery to my Node.JS server in Node.JS and Express, but it doesn't works!</p>
  
  <pre><code>var express = require('express')
  var app = express();
  app.listen(8888);
  
  app.configure(function(){
  
     app.use(express.bodyParser());
     app.set('views',__dirname + '/views');
     app.set('view engine', 'ejs');
     app.use(express.static(__dirname + '/public'));
     app.use(express.cookieParser());
     app.use(app.router);
  
  });
  
  app.get('/', function (req, res){
  
     res.render('ajax.ejs');
  
  });
  
  app.post('/ajax', express.bodyParser(), function (req, res){
  
     console.log(req);
     console.log('req received');
     res.redirect('/');
  
  });
  </code></pre>
  
  <p>And this is the <code>ajax.ejs</code>:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;script src="http://code.jquery.com/jquery-1.6.2.min.js"&gt;&lt;/script&gt;    
    &lt;script type="text/javascript"&gt;
  
        $('#enter').click(function(){  
  
       $.ajax({ 
             url: '/ajax',
             type: 'POST',
             cache: false, 
             data: { field1: 1, field2: 2 }, 
             success: function(data){
                alert('Success!')
             }
             , error: function(jqXHR, textStatus, err){
                 alert('text status '+textStatus+', err '+err)
             }
          })
       });            
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form&gt;
     &lt;input type="button" id="enter" value="Enter"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>When the <code>ajax.ejs</code>is loaded, there isn't any output in the console, so, the post request didn't work. What can I do?</p>
  
  <p>Thanks advance!</p>