S
S
Senseich2018-02-02 23:42:08
PHP
Senseich, 2018-02-02 23:42:08

How to use handler data after ajax request?

I'm trying to deal with Ajax, I ask you not to swear much))
I want to understand how to operate with data from the handler and what is it all about?

There is such a problem: there is a registration form on the "Test" page, I press the registration button and send the data with Ajax to the test.php handler, where a random n-number is generated and sent to the phone indicated in the registration form.

$.ajax({
  url: "test.php",
  success: function(data){
   Появляется модальное окно;
  }
});


test.php file:
<?
$chislo = рандомное число;
отправили на телефон
?>


1) How to understand what the handler returns?
2) Can this $chislo variable be used on this page after submission? (in the modal window, a person will enter a number from the SMS and you need to compare it with this $chislo variable.)

Please don't swear too much, I want to understand the basics! In particular, the concept "the handler returns data, what data, where does it return, how do I continue to work?"

I may be doing this wrong, please correct me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zvonok1337, 2018-02-02
@zvonok1337

The question is difficult to explain without knowledge of the theory.
I recommend implementing this script without JS, and only then, when .php is ready, implement ajax
1. To understand what the .php file returns, you need to see its code. It would be nice if you attached it here. Commonly used functions for debugging: var_dump, print_r (type them into google and you will see a link to php.net)
2. Of course you can save it, and in various ways, here are some of them: sessions, saving to a text file, saving to a database
Choose to taste :)
Links
php.net/manual/ru/features.cookies.php
php.net/manual/ru/session.examples.basic.php
php.net/manual /en/function.file-put-contents.php
php.net/manual/en/book.mysql.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question