R
R
RushV2018-07-30 22:08:39
AJAX
RushV, 2018-07-30 22:08:39

How does this ajax code work?

Hello!
Helped wrote code, forms but I can't understand how it works

// Отправить номер на сервер
    sendNumber (number) {
    	$.ajax({
        url: '/path/to/file', // Куда отправить
        type: 'default GET (Other values: POST)', // Каким методом
        dataType: 'json',
        data: {
        	number
        }
      })
      .done(() => console.log("success"))
      .fail(() => console.log("error"));
    }

Could you explain how this code works.
What else do I need to do to run this form.
The task was like this How to implement such a menu for dialing a number on JQWERY?
Good people helped a lot thanks to them!
I have nowhere to go with Ajax.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafeuri1989, 2018-09-07
@kafeuri1989

When submitting the form, you call the sendNumber function, having previously grabbed the filled
url number: '/path/to/file', - you write the path to the php file of the
type:'POST' handler
in this file
<?
if ($_POST)
{
mail('[email protected]','Subject',$_POST['number']);
echo 'Thank you';
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question