K
K
Kagtaviy2016-05-16 23:47:51
go
Kagtaviy, 2016-05-16 23:47:51

How to return response after successful completion of ajax function to script?

hello there is a form

<form method="POST" id="cnw" action="javascript:void(null);" onsubmit="call()">
                  <div class="form-group">
                    <label>1</label>
                    <input type="text" name="1" class="form-control" maxlength="20" placeholder="1">
                  </div>
                  <div class="form-group">
                    <label>2</label>
                    <input type="text" name="2" class="form-control" placeholder="2">
                  </div>
                  <div class="form-group">
                    <label>3</label>
                    <textarea class="form-control" name="3" rows="3" maxlength="63" placeholder="3" style="margin: 0px -0.5px 0px 0px; height: 98px; width: 487,5px;"></textarea>
                  </div>

                  <button type="submit" class="btn btn-default">Отправить</button>
                </form>

And ajax script:
function call() {
    var msg   = $('#cnw').serialize();
        $.ajax({
          type: 'POST',
          url: 'mcnews',
          data: msg,
          success: function(data) {
            aler('Окей')
          },
          error:  function(xhr, str){
      alert('Возникла ошибка: ');
          }
        });
    }

Then I process the forms in go, transfer them to the database, and after successful completion, I need to display an alert.
Can you please tell me how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fastpars, 2016-05-17
@Kagtaviy

func(w http.ResponseWriter, r *http.Request) {
// ...

// OR
  w.Header().Set("Content-Type", "text/plain")

// OR
  w.Write([]byte("This is an example server.\n"))

// OR
  fmt.Fprintf(w, "%s", "some string")
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question