gpt4 book ai didi

php - Cakephp + Jquery : how to user jquery methods?

转载 作者:行者123 更新时间:2023-12-01 05:58:04 25 4
gpt4 key购买 nike

我的问题很简单。

我有很多链接,例如:

$this->Html->link(__('Calculer'), 'log_import/'.$suivi['Suivi']['date'], array('class' => 'logImport')

如您所见,我的“a”标签的 href 属性在每个链接上都会发生变化(例如“2012-01-01”、“2012-10-15”等日期)

当我点击链接时,jquery 代码正在执行:

$this->Js
->get('.logImport')
->event('click',
$this->Js->request(
array('action' => '$(this).attr("href")'),
array('async' => true,
'update' => '#test')
));

我收到一个错误,因为 ajax 请求使用的 URL 是:

/suivis/$(this).attr("href")

而不是:

/suivis/log_import/2012-01-01

最佳答案

是的,最后我在 JS Helper 缓冲区中使用了“纯”jquery 代码。

这是我的代码(您可以直接使用 $(this).attr 并绕过每个循环;-)

$this->Js->buffer('
$(".logImport").click(function(event) {
event.preventDefault();
$.ajax({
url: $(this).attr("href"),
})
.done(function(){
alert("OK");
})
.fail(function(){
alert("FAILED");
});

});
');

顺便说一句,如果有人知道的话,我仍然对答案感兴趣......

关于php - Cakephp + Jquery : how to user jquery methods?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13517589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com