How to get ajax post request value in Go lang? -


I'm working in Go . The following code to handle client requests. Package main import ("net / http" "fmt") func main () {http.HandleFunc ("/", func (w http.ResponseWriter, R * http.Request) { fmt.Fprintf (w, "& lt; html> gt; & gt; head & gt; & lt; script & gt; function createGroup () {var xmlhttp, number = document.getElementById ( 'phoneNumber'). value, email = document.getElementById ( 'emailId'). value; var value = {}; values.number = phoneNumber; values.email = emailId; if (window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest ();} and {xmlhttp = new ActiveXObject ( 'Microsoft.XMLHTTP');} xmlhttp.open ( 'post', 'createGroup', true); xmlhttp.send (values.toString ());} & lt; / script & gt; & lt; / head & gt; & lt; body & gt; & lt; h1 & gt; group & lt; / h1 & gt; & lt; input type = 'text' name = 'phone number' id = ' In the form, click on the button '/' CreateGroup () '& gt; Create Group & lt; / /; & gt; Input Type =' Email 'id =' emailId 'name =' emailId '/ & gt; & lt; button & gt; & lt; / body & gt; & lt; / html & gt; ")}) Actiteepikhandlifuns (" / Kreategrup "blow (and Actiteepikresponsevriter, and * Actiteepikrikvest) {Fntkprintln (R) // Try to get user information} Terror (http.ListenAndServe (": 8080", zero))}

note

Customers: There are two text boxes to get the phone number , email and createGroup buttons.

  1. If a user clicks on creategroup , / creategroup Is triggered by using.

  2. createGroup request is handled in the server (go)

    problem

    the phone number in the server side How to get more emails?

    I printed the request in the / createGroup handler but the values ​​are unavailable.

      Output: & amp;; POST / createGroup HTTP / 1.1 1 1 map [Accept: [text / html, application / xhtml + xml, application / xml; Q = 0.9, * / *; Q = 0.8] encoding-encoding: [jizip, diffet] content-length: [15] content-type: [text / plain; charset = UTF-8] connection [keep-alive] Pragma: [No-Cache] Cache-Control: [No-Cache] User-agent: [Mozilla / 5.0 (x 11, Ubuntu, Linux X 86_64, RV .25.0) Gecko / 20100101 Firefox / 25.0] Accepted language: [N-US, N; Q = 0.5] Referrer: [http: // localhost: 8080 /]] 0xc200099ac0 15 [] Bad Localhost: 8080 Map [] Map [] & lt; Zero & gt;   

    Any assistance will be grateful.

    r.ParseForm () fmt.Println (r.Form) fmt.Println (r.FormValue (" email "))})

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -