I've been searched about this problem over stackoverflow, but couldn't get any answer that solves my problem.
This is even sample code in my node.js book. I don't know why this is not working and I want to sue author of this book. He gave me lot of stress.
1] Code in server.js
app.post('/products', function (request, response){
console.log(request.params);
var name = request.params.name;
var price = request.params.price;
var item = {
name : name,
price : price
};
items.push(item);
response.send({
message : 'Data pushed',
data : item
});
});
2] Code in index.html
$('#post').click(function(){
console.log($('#name').val());
console.log($('#price').val());
$.ajax({
url:'/products',
type:'post',
dataType : 'text',
data : {
name : $('#name').val(),
price : $('#price').val()
},
success : function(data){
$('#output').val(data);
}
});
});
I can see correct data which I put in #name and #price in console of Chrome browser by console.log. But I can't see any data in server.js by console.log(request.params). console.log(request.params), console.log(request.params.id), console.log(reqeust.params.price) all returns 'undefined' Why does it return undefined? I tried lots of things I searched through internet, but nothing solved. What's the problem?