I submit the form data to the node.js server using the ajax function on the html page, if I use the post method, I do not see anything in the console, as well as in the warning field.
if i use get method in ajax file and app.js i get warning like hello but i am not any msg in app.js server console
app.js
var express = require('express')
, routes = require('./routes')
, manage = require('./routes/user')
, http = require('http')
, path = require('path');
var app = express();
app.post('/filter', routes.filter);
http.createServer(app).listen(app.get('port'), "172.29.59.65", function(){
console.log('Express server listening on port ' + app.get('port'));
});
index.js
exports.filter = function(req, res){
req.on('data', function (chunk) {
console.log("Received body data", chunk.toString());
})
req.on('end', function() {
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.end("hello");
})
};
client.html
<html>
<head>
<script>
function myFunction() {
var region=document.getElementById("region").value;
var os=document.getElementById("os").value;
alert(region+os);
var data = {};
data.region = region;
data.os = os;
$.ajax({
type: 'POST',
jsonpCallback: "callback",
datatype: 'jsonp',
data: JSON.stringify(data),
url: 'http://172.29.59.65:3000/filter',
success: function(data) {
alert(data);
console.log(JSON.stringify(data));
},
error: function (xhr, status, error){
console.log('Failure');
alert("failure");
},
});
}
</script>
</head>
<body>
<form>
<input type="text" id="region" name="region"/>
<input type="text" id="os" name="os"/>
<input type="button" value="search" class="fil_search" onclick="myFunction()"/>
</form>
</body>
</html>
my problem is sending data to node server and receiving data from node server on html page how to do it. please help me out of this.