Welcome aboard! We are happy you are here and wish you good net-raft!
// index.html
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
$('#mylink').click(function(e){
e.preventDefault();
var data = {};
data.title = "title";
data.message = "message";
$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: 'http://localhost:3000/mynodecode',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
}
});
});
});
</script>
</head>
<body>
<div id="mydiv"><a href="#" id="mylink">Click</a></div>
</body>
</html>
// myserverfile.js
var express = require('express');
var app = express.createServer();
app.use(express.bodyParser());
app.post('/mynodecode', function(req, res){
var obj = {};
console.log('body: ' + JSON.stringify(req.body));
res.send(req.body);
});
app.listen(3000);
The most helpful NODEJS solutions