为什么你的方法不起作用
这不起作用的实际原因是您正在更改当前jquery ajax 对象的 url 属性,而不是未来对象的 url。当您看到生成的 html/js 时,这变得很明显:
关联:
<a href="#" class="bookmark_off" id="bookmark-btn">value-of-text</a>
事件监听器(以下通常在最后一个找到<script>,</body>我也添加了一些评论):
$('body').on('click','#bookmark-btn',function(){
    jQuery.ajax({'data':{'id':1},'type':'GET',
        'success':js:function(data){
            if (data.status == "success"){
                //attempt to dynamically change the URL
                this.url = "/core/bookmark/delete";
                $("#bookmark-btn").toggleClass("bookmark_on").toggleClass("bookmark_off");
            }
        },
        'url':'/project-name/index.php/core/bookmark/create', // this url is used repeatedly
        'cache':false
    }); // ajax call ends
    return false; // click handler ends
});
上面的监听器显示,每次点击都会创建/完成一个新的ajax 对象/调用,因此每次只更改该对象的 url,但不会更改下一个对象,该对象将为下一次调用创建。对于下一次调用,将使用相同的旧 url,即 : 'url':'/project-name/index.php/core/bookmark/create',。
解决方案
有一种方法可以“动态更改 ajax 链接的 url”。而不是使用CHtml::ajaxLink,使用普通CHtml::link的,但添加了clientChange选项。clientChange选项包含在第三个参数to 中,CHtml::link即within htmlOptions。这样我们就可以为 ajax 调用指定一个动态 url,它将使用为 ajax 调用生成href的<a>标签,而不是静态 url。
一个例子(阅读代码中的注释):
echo CHtml::link($text, array('/core/bookmark/create'), array(
    // the htmlOptions array, with clientOptions included
    'id'=>'bookmark-btn',
    'class' => 'bookmark_off',
    'return' => false, // this is already false by default - read documentation
    'ajax' => array( // now specify the ajax options, with a dynamic url
        'url' => 'js:$(this).attr("href")', // this takes the href property of
                // the <a> tag that is generated for this CHtml::link
        'data' => array('id' => $id),
        'custom_data_passed_to_ajax_object' => 'js:this', // this is important,
                // here we pass link, <a> tag, for use within the ajax object
        'success'=>'function(data){
            if (data.status == "success"){ 
                // now change the href of the <a> we passed in custom_data_passed_to_ajax_object
                $(this.custom_data_passed_to_ajax_object).attr("href",
                    "'.$this->createUrl('/core/bookmark/delete').'");
                $("#bookmark-btn").toggleClass("bookmark_on").toggleClass("bookmark_off");
            }
        }'
    )
));
您实际上ajaxLink也可以将上述解决方案调整为:
echo CHtml::ajaxLink($text,
    'js:$(this).attr("href")', // this will be generated as 'url':$(this).attr("href")
    array(// ajax options, remember to pass the reference to the <a>,
        // i.e custom_data_passed_to_ajax_object in the above snippet
    ),
    array(
        'href'=>$this->createUrl('/core/bookmark/create'), // your actual url
        // rest of htmlOptions
    )
);
至于您的最终目标“实现一个书签按钮,在每次点击时在添加和删除功能之间切换”,其他人已经给了你足够的提示。