Javascript CHtml链接为父链接返回null
我使用Chtml::Link创建了一个url,如下所示:Javascript CHtml链接为父链接返回null,javascript,php,jquery,yii,yii-components,Javascript,Php,Jquery,Yii,Yii Components,我使用Chtml::Link创建了一个url,如下所示: CHtml::link("Remove", '#', array('class' => 'delete'))) $('.delete').click(function(e) { e.preventDefault(); $.ajax({ url:'" . $this->createUrl('//shop/shoppingCart/delete') . "', type : 'GET',
CHtml::link("Remove", '#', array('class' => 'delete')))
$('.delete').click(function(e) {
e.preventDefault();
$.ajax({
url:'" . $this->createUrl('//shop/shoppingCart/delete') . "',
type : 'GET',
data: {id: $position},
success: function(result) {
console.log($(this).parent());
},
});
});
现在,当用户单击它时,我会发送一个ajax请求,如下所示:
CHtml::link("Remove", '#', array('class' => 'delete')))
$('.delete').click(function(e) {
e.preventDefault();
$.ajax({
url:'" . $this->createUrl('//shop/shoppingCart/delete') . "',
type : 'GET',
data: {id: $position},
success: function(result) {
console.log($(this).parent());
},
});
});
它总是记录“undefined
”,但链接位于td
我要做的是删除包含链接的行。任何新的方法都是受欢迎的。请帮忙 ajax调用的success函数中的this是与click函数中的this相比的另一个
this
。因此,您可能找不到该此
的父级
我猜您是在试图找到元素的父元素来更新html,对吗?为什么不改用Chtml::ajaxLink,然后可以使用update属性:
Chtml::ajaxLink(
'Remove',
$this->createUrl('//shop/shoppingCart/delete'),
array(
'update' => "$('.delete').parent()", // or anything like this
'data' => array(
'id' => $position,
)
),
array(
'class' => 'delete'
)
)