I am having an issue in node.js getting the post variable from a post done via a JSON function.
Edit: I can see the form post in Chrome's inspector. The form post is good and well formatted.
The server bit:
app.use(express.bodyParser());
app.post('/user', function (req, res) {
var tempSession = req.body.tempSession;
console.log(tempSession);
}
The post from the JSON function:
function postJSONP(url, params, method) {
method = method || "post"; // Set method to post by default, if not specified.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", url);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
The post that call the JSON function:
function LoginSubmit() {
var action = 'login';
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var tempSession = generateSession();
postJSONP('/user?callback=none&action=' + action + '&user=' + username,{"password":password, tempSession:tempSession});
}
The form submit from HTML:
<input id="submit" name="submit" type="submit" value="Login" onclick="LoginSubmit();">
The result from Node.js console:
undefined