Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Front End

// js / jquery
var content = {
    info : 'this is info',
    extra : 'more info'
}
$.ajax({
    type: 'POST',
    url: '/tosave',
    data: content
}); 

Node

// app.js
app.post('/tosave', function(req, res){
    fs.writeFile('/saved.txt', function(err, data){})
});

This saves to the file as [object Object]. I get the same result when I use JSON.stringify() on content before sending it through the ajax request. However, if I stringify it in node.js it successfully saves as {"info":"this is the info","extra":"this is extra"}.

My question is why this happens? Also, how would I go about converting it to a json string before the ajax request?

share
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.