N
N
Nikolai Novosad2015-12-01 00:17:07
Yii
Nikolai Novosad, 2015-12-01 00:17:07

Yii2 Pass variable from Ajax to controller?

Hello.
Can you please tell me how to pass the value of the variable to the controller from this ajax script?

$(document).ready(function(){
   $("#events-select").change(function(){
     var month = $("#events-select :selected").val();
       $.ajax({
          type: "POST",
           url: "web/site/events",
           data: {"month": month},
           cache: false,
           success: function(response){
               $(".events").html(response);
           }
       });
   });
});

Through alert, the variable is displayed, but when I try to do this in the controller:
public function actionEvents()
{
    if (isset($_POST)){
            $meet = $_POST['month'];
        }
    return $this->render('events');
}

I get the error Undefined index: month
How to implement this correctly?
Thanks in advance.

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