U
U
unknown4042019-12-02 22:53:13
API
unknown404, 2019-12-02 22:53:13

Explain how to send data from the form, and connect to the API?

Good evening, I was given an API to connect, I need to send data from an html page in the "form" format to the server
5de566884b2a0941703456.png

. I have a form with data.
5de566d7018f2655980104.png

How can I do it right. Tell me please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WStanley, 2019-12-03
@WStanley

Use jquery for example link
Collect data from form

let data = new FormData();
data.append('name', $('#name').val())
...

On form event
$('.formClass').submit(function( event ) {
  event.preventDefault();
  # Нажатие кнопки submit
  # formClass - класс формы
});

to send them
$.ajax({
    url: 'url',  # url куда отправляем
    headers: {  },  # Заголовки
    type: 'POST',  # Метод отправики
    data: data,  # Данные отправки с формы
    beforeSend: function () {
        # Действия перед отправкой
    },
    success: function (response) {
        # Действия в случае удачного ответа
    },
    error: function (response) {
        # Действия если ошибка
     }
 });

It would still be nice to validate the form, but that's a completely different story.

A
Alex, 2019-12-03
@streetflush

htmlbook.ru/html/form/action

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question