Answer the question
In order to leave comments, you need to log in
How to send ajax request in yii?
Help with ajax request.
The JS request itself:
var siteUrl = window.location.href; // Сюда попадает: http://mysite.ru/
var offset = new Date().getTimezoneOffset();
$.ajax({
type: 'post',
url: siteUrl,
data: 'offset='+offset,
success: function(data){
alert(data);
},
error: function(request, status, error) {
alert(request.status); // прилетает 400 код ошибки
}
})
public function actionIndex()
{
if (Yii::app()->request->isAjaxRequest){
echo "response " . $_POST['offset'];
}
}
return [
'' => 'feed/default/index',
]
Answer the question
In order to leave comments, you need to log in
скорее всего из-за crfs_token-а, либо шлите GET либо добавляете токен в POST или отключите проверку в экшене (самый не верный вариант)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question