I am using extensively the clementinejs boilerplate to do this project.
So , I would need to substitute the button of the original with a form in my tweak.
For a first check I pass the HttpRequest (Post) by hand in the method xmlhttp.send().
So, the code in the method ajaxRequest of the file ajax-functions.js:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
callback(xmlhttp.response);
}
};
xmlhttp.open(method, url, true);
xmlhttp.send("foo=bar&lorem=ipsum");
And the code in clickHandle.server.js to insert the query string of xmlhttp.send(“foo=bar&lorem=ipsum”)) is.
var Users = require('../models/users.js');
function ClickHandler () {
.......
this.addClick = function (req, res){
Users.create({text: req.body}, function (err, res) {
if (err) return err;
console.log("saved!")
})
}
}
The post send a message of saved! in the console and a check in the mongo console shows that it is been add up a new document, but nothing about the query string passed “foo=bar&lorem=ipsum”. I tried different method of mongoose, but the same. A check in the req parameter of ClickHandler, console.log(req), returns [object Object]