N
N
Nikita Kolosov2013-11-15 06:24:40
Yii
Nikita Kolosov, 2013-11-15 06:24:40

JS issue when loading content via AJAX in Yii framework?

There is the following code:

echo CHtml::ajaxLink(
        $title,
        array('controller/action', 'id' => $id),
        array(
          'success' => 'js:function(data) {$("#container").html(data);}',
        )
      );

In controller/action is called
$this->renderPartial('view', array('model' => $model), false, true);

If you remove $processOutput = true, then those scripts that are called in the view do not work. For example, the TbEditableField widget (yii-booster) does not work. If left - after the ajax call, those that are already on the original page partially fall.
Question: is there any way to solve this problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sets, 2013-11-16
@sets

Can you figure out why those on the original page are falling? In such cases, I use $processOutput = true and am satisfied. There are two types of problems. Firstly, I can re-pull some js from assets. To do this, in the loadable view, indicate that some things do not need to be loaded, they are already on the parent page. Type
Another issue is the id match. Yii, for all kinds of manipulation, hangs an id on each widget automatically if they are not specified. They are numbered on the same page, so they are all different, but the loaded ones are numbered again, as a result, several id=yw0 divs, for example, and different handlers for this same yw0 appear on the same page. Specify at least the id of the loaded widgets yourself.

V
Vladimir, 2013-11-15
@merdoc

I think it will help http://www.yiiframework.ru/doc/cookbook/ru/js.ajax

A
Alexey Smolyanov, 2013-11-15
@littledev

I also toyed with this issue and rewrote the events with handles in js files, I really didn’t like the description of the Ajax link for half a page, and even in the view, but what else can and should be seen: http://www.yiiframework.com/doc /api/1.1/CHtml#clientChange-detail http://www.yiiframework.com/doc/api/1.1/CHtml#liveEvents-detail

pay attention to the live option, it is just for event delegation

D
DuD, 2014-05-20
@DuD

In the base class for all controllers, you can do something like this. By disabling scripts you don't need.

if (Yii::app()->request->isAjaxRequest)
{
    $cs = Yii::app()->clientScript;
    $cs->scriptMap = array(
        'jquery.js' => false,
        'jquery-ui.min.js' => false,
        'jquery-ui.css' => false,
    );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question