title: How to use ajax post method with golang server side endpoint?
body: <h2></h2>
  <p>I need some help to apply my endpoint that's working in Postman to work with client side
  using ajax I tried some of the online snippet codes but it seems I have an issue in my own code that needs to be reviewed.</p>
  <ol>
  <li>Server Side (Golang Code)</li>
  </ol>
  <pre><code>type DirectMessage struct {
      FullName   string `json:&quot;fullName&quot;`
      Email      string `json:&quot;email&quot;`
      Message    string `json:&quot;message&quot;`
      ID         int     `json:&quot;id&quot;`
  }
  
  func AddNewDM(w http.ResponseWriter, r *http.Request) {
      db := ConnectDB()
      defer db.Close()
      dm := DirectMessage {}
      Decoder := json.NewDecoder(r.Body)
      err := Decoder.Decode(&amp;dm)
      if err != nil {
          log.Fatal(err)
      }
  
      db.Create(DirectMessage {FullName: dm.FullName, ID: dm.ID, Email: dm.Email, Message:dm.Message})
      fmt.Fprintf(w, &quot;New DM created&quot;)
  }
  func httpRequests() {
      router := mux.NewRouter().StrictSlash(true)
      router.HandleFunc(&quot;/api/new_dm/{id}/{fullName}/{email}/{message}&quot;, AddNewDM).Methods(&quot;POST&quot;)
      http.ListenAndServe(&quot;:9090&quot;, router)
  }
  func main() {
      db := ConnectDB()
      db.AutoMigrate(&amp;DirectMessage{})
      defer db.Close()
      templates = template.Must(template.ParseGlob(&quot;templates/*.html&quot;))
      fs := http.FileServer(http.Dir(&quot;./templates&quot;))
      http.Handle(&quot;/templates/&quot;, http.StripPrefix(&quot;/templates/&quot;, fs))
      httpRequests()
  }
  </code></pre>
  <p>Form HTML - JS</p>
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;html&gt;
          &lt;header&gt;
              &lt;title&gt; Add New User &lt;/title&gt;
          &lt;/header&gt;
           &lt;body&gt;
              &lt;form&gt;
                  &lt;label for=&quot;fullName&quot;&gt;FullName:&lt;/label&gt;&lt;br&gt;
                  &lt;input type=&quot;text&quot; id=&quot;FullName&quot; name=&quot;FullName&quot;&gt;&lt;br&gt;
                  &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;&lt;br&gt;
                  &lt;input type=&quot;email&quot; id=&quot;email&quot; name=&quot;email&quot;&gt;&lt;br&gt;
                  &lt;label for=&quot;message&quot;&gt;Message:&lt;/label&gt;&lt;br&gt;
                  &lt;input type=&quot;message&quot; id=&quot;message&quot; name=&quot;message&quot;&gt;&lt;br&gt;
                  &lt;button id = &quot;submit_form&quot; class=&quot;form_button&quot; type=&quot;submit&quot;&gt;Send It!&lt;/button&gt;
              &lt;/form&gt;
          &lt;body&gt; 
      &lt;/html&gt;
  </code></pre>
  <h2></h2>