A
A
avdoshka2020-05-21 11:06:33
PHP
avdoshka, 2020-05-21 11:06:33

What code should be written in ajax.php?

I need to do post processing, what code do I need to write in the ajax.php file so that when the ask button is pressed, answers to questions are displayed like here5ec63676adb5f334879119.png html

<div style='margin: auto; width: 480px; padding-top: 10px'>
        <input type='text' id='question' name='question' class='numerologiya_input' placeholder='Введите вопрос'/>
        <div class='sendquestion' style='width: 193px; height: 82px; margin: auto; background: url(/images/sprosit.png); cursor: pointer'></div>
      </div>
      <script>
        $('.sendquestion').click(function(){
          if( $('input[name=question]').val()=='' )
          {
            $('#answer').html('Зачем беспокоить шар по пустякам?').fadeIn(1500).fadeOut(1000);			
          }
          else
          {
            $('#answer').hide();
            $.ajax({
              url: '/ajax.php',
              type: 'POST',
              data: {
                'question': $('#question').val()
              },
              success: function(html){
                $('#answer').html(html);
                $('#answer').fadeIn(1500);
              }
            });
          }
        });
      </script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Trubchaninov, 2020-05-21
@Ssssory

$arrAnswer = [
    'Твой разум затуманен',
    'Никто не будет писать за тебя весь код',
    'Возможно, стоит поднять свой скилл',
    'Не огорчайся, можно спать и 2 часа в день',
    'Это пройдёт',
];

return $arrAnswer[rand(0,4)];

This code will work, but I don't think it's what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question