P
P
Petr Fronin2016-03-11 17:03:44
JavaScript
Petr Fronin, 2016-03-11 17:03:44

Why doesn't Yii2 paired with jQuery (aJax) work?

AJax request not working, what could be the reason?

We connect in views:

$script = <<< JS
$.ajax({
  url: 'mysite.ru/site/message',
  success: function(data) {
    alert(data);
  }
});
JS;
$this->registerJs($script, yii\web\View::POS_READY);


In controller:
public function actionMessage()
{
        echo 'Проба';
}


jQuery is included built into Yii2.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor, 2016-03-11
@master2016

Trace this code (and the jQuery include code) in the resulting html code of the page to begin with.
Well, look in Firebug or something - is Ajax knocking here - mysite.ru/site/message

V
Vladimir Soldatov, 2016-03-17
@TPbIHTPABA

does the url line bother you?
I think your script is trying to get data from domen.com/mysite.ru/site/message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question