S
S
sershan72020-04-11 19:43:42
JavaScript
sershan7, 2020-04-11 19:43:42

How to get data from input to send to whatsapp messages via ajax?

There is a script that sends a message to whatsapp

<script>
$( document ).ready(function() {
// URL для запроса POST /message
    var url = 'https://eu43.chat-api.com/instance**********/message?token=**********';
    var data = {
        phone: '7**********', // Телефон получателя
        body:  'Здесь должно быть сообщение', // Сообщение
    };
    // Отправим запрос при нажатии на кнопку
    $( ".button" ).click(function() {
    $.ajax(url, {
        data : JSON.stringify(data),
        contentType : 'application/json',
        type : 'POST'
    });
    });
});
</script>

And there are inputs that are filled in by the client to send information about the order to connected partners (cafes, restaurants) by phone number in whatsapp to form and deliver the order
<input name="name" class="t-input">
<input name="phone" class="t-input">
<input name="address" class="t-input">
<input type="hidden" name="recipient" value="7**********"> //Номер телефона получателя информации о заказе в whatsapp

Now the task is to send information about the order to whatsapp, which is contained in the input values ​​(name, phone, address) to the recipient number (recipient) and put names before each input value (except recipient), that is, Name:, Phone number:, Address: new line. The recipient value (recipient) must be inserted into phone, and the remaining input (name, phone, address) into data.

Example of a received message:
Name: Dmitry
Phone: +79999999999
Address: Kazan, Bauman street, 20, apartment 19
Order: Pizza "Margarita"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question