L
L
Lumore2016-04-25 12:44:48
JavaScript
Lumore, 2016-04-25 12:44:48

Error 500, ajax yii2?

You need to add a city to the session by pressing a certain button. I wrote this js code:

$('[data-search-list-for="city"]').click(function() {
    var $city = $(this).data('dataSearchListItem');
    $.ajax({
        url: '/site/default/set-city',
        type: 'post',
        data: {
            city: $city
        }
    });
});

action:
public function actionSetCity()
    {
        if (Yii::$app->request->isAjax) {
            $data = Yii::$app->request->post();
            $session = Yii::$app->session;
            $session->open();
            $session->set('city', $data['city']);
        } else {
            return $this->redirect(['/site/default/error']);
        }
    }

In the console it gives a 500 error, where did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NikColt, 2016-04-25
@NikColt

Look in the logs.. runtime/logs/app.log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question