I have a POST request that I want to process:
var app = require('express')();
var bodyParser = require('body-parser');
app.use(bodyParser());
. . .
app.post('/signup', function(req, res) {
console.log('name: ' + req.body.name);
console.log('email: ' + req.body.email);
. . .
});
All seems well and dandy.
My client:
<html><body>
<form>
Name:<br>
<input type=text name=name><br>
Email:<br>
<input type=text name=email><br>
<input id=submit type=submit value=Submit>
</form>
<script type=text/javascript src=https://code.jquery.com/jquery-3.0.0.min.js></script>
<script>
$('input#submit').click(function() {
$.ajax({
url: 'http://localhost:5000/signup',
type: 'post',
dataType: 'json',
data: $('form').serialize(),
success: function(data) {
console.log('response:', data);
}
});
return false;
});
</script></body></html>
The problem? success
is never called in the client. Eventually, Chrome JS-debug window shows: net::ERR_EMPTY_RESPONSE
.
I have tried doing res.send(200)
, res.send('')
and res.end()
in the server, but without success.
My Node.js version is 4.2.6, and I think my Express version is 4.4.1.