I'm trying to post form data in another view in my node/express application. I'm using Jade as the view engine.
- Form is posted
- Handler passes the req.body to the res.body
- view is rendered
My question is how do I access this res.body object? How to I get at the data? I'm trying to use user input to draw some graphs.
Code below
barchartEntry.jade
form(method="POST")
#dynamicInput
input(type="button" value="Add New Bar" onClick="addInput('append');")
input(type="button" value="Remove Last Bar" onClick="removeInput();")
br
label(class="barTitle") Bar 1
label(class="bartTtle") Value
input(type="text" name="myInputs[]")
label Label
input(type="text" name="myLabel[]")
br
#append
input(type="submit" value="Submit")
include copyright
Route Handler
exports.postBarchartentry = function postBarchartentry(req, res){
res.body = req.body;
res.render('barchart');
};
local JS on new view
$( document ).ready(function() {
var values = ?
var labels = ?
var canvas = document.getElementById("canvas").getContext("2d");
var Width = canvas.canvas.clientWidth;
var Height = canvas.canvas.clientHeight;
var padding = 30;
function fillBackground(color){
canvas.fillStyle=color;
canvas.fillRect(0,0,Width,Height);
}
function fillAxes(){
canvas.beginPath();
canvas.moveTo(padding, padding);
canvas.lineTo(padding, Height-padding);
canvas.lineTo(Width-padding, Height-padding);
canvas.lineWidth = "3"
canvas.strokeStyle="black";
canvas.stroke();
}
function draw(){
fillAxes();
}
draw();
});
As you can see, I'm trying to get the inputted form data to be accessable in my last script