HIi 伙计们,我有一个问题,请帮助我,我想使用 ajax 调用将一些数据发送到我的控制器,我已经编写了所有代码,但对于数据字段
<?php echo $this->Js->get('.menu')->event('click',$this->Js->request(array('controller' => 'restaurants', 'action' => 'getItem'),array('async' => true,'method'=>'POST','update' => '#HFNames','data'=>'$(this).attr(id)')),false); ?>
当 ajax 调用命中时,它将"$(this).attr(id)"作为参数,但我需要 cureent click 的值
JS助手生成这个如果我们从这个生成的脚本中删除该双引号,那么它就可以工作 data: "$(this).attr(id)",为什么这会被引用
<script type="text/javascript">
$(".menu").bind("click", function (event) {
$.ajax({
async: true,
data: "$(this).attr(id)",
dataType: "html",
success: function (data, textStatus) {
$("#HFNames").html(data);
},
type: "POST",
url: "'/foodkingkong'/restaurants'/getItem"
});
return false;
});
试试这个。
echo $this->Js->buffer('$(".menu").bind("click", function (event) {
$.ajax({
async: true,
data: $(this).attr(id),
dataType: "html",
success: function (data, textStatus) {
$("#HFNames").html(data);
},
type: "POST",
url: "/foodkingkong/restaurants/getItem"
});
return false;
});'
);
嗨,
Himanshu,我们计划直接使用 jquery 做同样的事情,但只想通过 cakephp bind 函数做同样的事情。如果我们在缓冲区中传递 js,会有什么区别。