Ajax request

hello :)

Have problem with sending ajax data.

piece of my js code


  document.onkeydown = function(e) {  

     if (e.keyCode == 37) 

        {

            data = 'left arrow';  

            $.ajax({ 

                type: "POST", 

                url: "index/getAjax", 

                data: data

            });


        }

}

I expect to get $_POST at indexController, actiongetAjax method


    public function actiongetAjax()

    {

        echo "POST Comes: ".var_dump($_POST);

    }

due to console, Headers and data sended correct and request made.

What should i do to fix that?

Thanx!

Hi hutsi, welcome to the forum.

Try this:




    $.ajax({ 

        type: "POST", 

        url: "index/getAjax", 

        data: {key : "left arrow"}

    });



Then you will get ‘left arrow’ as $_POST[‘key’]. :)

it’s rather a jquery issue, try this:


//data  = 'left key';

data = {keypressed: 'left key'};

softark, tyvm for greetings :)

problem solved!

thanx again