node. JS study Note (2)--Submit form

Source: Internet
Author: User

Description (2017-5-2-11:42:33):

1. index.html

1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4     <MetaCharSet= "UTF-8">5     <title>Document</title>6 </Head>7 <Body>8     <formAction= ""Method= "GET">9         <inputtype= "text"name= "username"><BR/>Ten         <inputtype= "text"name= "Password"><BR/> One         <inputtype= "Radio"name= "Gender"value= "Male">male A         <inputtype= "Radio"name= "Gender"value= "female">female -         <inputtype= "Submit"name=""value= "Submit"> -     </form> the </Body> - </HTML>

2. Foo.js

1 varHTTP = require ("http");2 varurl = require ("url");3 varServer = Http.createserver (function(req,res) {4     //Console.log ("The server received the request" +req.url);5     varQueryobj = Url.parse (Req.url,true). query;6     varUsername =Queryobj.username;7     varPassword =Queryobj.password;8     varGender =Queryobj.gender;9 TenRes.end ("Server received form Request" + Username + password +gender); One }); AServer.listen (3000, "");

3. Output


(1) url.parse (url,true). Query is the latest method, True to convert a string to an object, without true being a string. The previous querystring deprecated.

node. JS study Note (2)--Submit form

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.