Answer the question
In order to leave comments, you need to log in
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
. I have a form with data.
How can I do it right. Tell me please
Answer the question
In order to leave comments, you need to log in
Use jquery for example link
Collect data from form
let data = new FormData();
data.append('name', $('#name').val())
...
$('.formClass').submit(function( event ) {
event.preventDefault();
# Нажатие кнопки submit
# formClass - класс формы
});
$.ajax({
url: 'url', # url куда отправляем
headers: { }, # Заголовки
type: 'POST', # Метод отправики
data: data, # Данные отправки с формы
beforeSend: function () {
# Действия перед отправкой
},
success: function (response) {
# Действия в случае удачного ответа
},
error: function (response) {
# Действия если ошибка
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question