javascript - How can I get express js to read forms -
javascript - How can I get express js to read forms -
i trying nodejs/expressjs form info sent using jquery $.ajax
function. know $http
there plus not practice have angular jquery stuck in requires new form element , jquery, have written test it.
i doing test because not find way or info on how form info (including files) without using body-parser doesn't back upwards multipart/form-data have read on web.
here code in in front end end
$scope.sendmsg = function () { var formdata = new formdata($('#form')); $.ajax({ url: '/test', type: 'post', data: formdata, cache: false, contenttype: false, processdata: false, success: function (data, status,something) { $scope.$apply(function () { console.log('data: ' + data); console.log('status: ' + status); console.log('something: ' + something); $scope.msgs.push({content : data}) $scope.msgtext = ''; }); }, error: function (data, error) { alert('did not work'); } }); }
and basic test in end
app.post('/test',function (req, res) { res.send(req.body.msg); });
you need utilize body-parser
grabbing input variables , connect-busboy file parsing. reason why need because nodejs civilization set smallest components people can mix , match modules against needs. in case need file parsing , rest of form data, need include both middlewares.
the body parser module used include file parsing functionality deprecated used techniques temporary files (and users tended utilize other modules instead).
javascript node.js express
Comments
Post a Comment