Answer the question
In order to leave comments, you need to log in
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
}
});
});
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']);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question