0

I wanna update div tag after ajax:

        $.ajax({
            type: 'GET', // or POST, no difference
            url: "<?php echo Yii::app()->createUrl('words/nextWord');?>",
            success: function(data) {
                // There need add code
            }
        })
    }

After ajax i have response whole page with change change and me need change word in this tags or substitute div. I tried use:

$('#word').load("<?php echo Yii::app()->createUrl('words/nextWord'); ?> #word");

Before code above i had

<span id="word" class="word">dog</span>

After code above i had

<span id="word" class="word">
    <span id="word" class="word"> good</span>
</span>
4

2 回答 2

0

此 url words/nextWord中的内容可能是

"<span id="word" class="word"> good</span>"

但它应该只返回“好”。所以 load 方法将内容插入其中。尝试直接在浏览器中调用该 url 并检查它返回的内容。

于 2013-03-08T09:02:27.880 回答
0

我不完全是你想要做的,但该.html()函数将替换元素的内容#word

$('#word').html("<?php echo Yii::app()->createUrl('words/nextWord'); ?>");
于 2013-03-07T15:32:50.030 回答