javascript - How to receive POST form data in node.js from client -
Hello friends I'm a newbie when it comes with web development, especially working with node.js, Want to know how I can get the data sent from the client through AJAX Post
The script below is what I've written to post the form data
This is a form of its own
& lt; Form style = "margin-top: 25%; margin-left: 30%" method = "post" verb = '/' & gt; & Lt; Input class = "input" type = "text" id = "user" required = "true" name = "user name" placeholder = "user name" & gt; & Lt; Input class = "button-1" style = "background: # 000" onClick = "ecoachSignIn ()" type = "submit" value = "sign in" & gt; & Lt; Div style = "margin-top: 10px" & gt; & Lt; Input class = "input" type = "password" id = "pass" name = "password" required = "true" placeholder = "password" & gt; & Lt; / Div & gt; & Lt; / Form & gt; node.js server code
router. Post ('/', function (request, ridge) {var request = requires ("request "), User_name = req.body.username, // It downloads the username directly from the form, I directly post the problem with the password from the Javascript password = req.body.password, // Username url = req.query The url; // is trying to get the url in my jQuery on the client side, but the console.log is not working ("user name =" + use R_name + ", password" + password "); request.get ({url: url}, function (error, feedback, body) {// more stuff with 'body' here (! Error & amp; response .statusCode == 200) {var json_body = JSON.parse (body); console.log (json_body); condition = Json_body.status; success = json_body.msg; fname = json_body.profile.fname; console.log ("hi "+ Fname"; // Print Username.Console.log ("Status" + Status); // Print the Status. Console.log ("Success" Success "); // Success Impressions}}); res. End ("yes"); }); My biggest problem is how to node it. JS Backend is processed on the server. My question is clear .... Thanks
Your server side code:
user_name = req.body.username, // This username is not found directly from the form Your customer side code:
< Pre> users:. $ ('# User') val (); Pass: $ ('#pass'). Val (); You call user and pass to the client, but username and password On the server you have to use the same name in both places.
This works when you normally use the form because the names match the attributes names that you use on the server.
Comments
Post a Comment