0

嗨伙计们我有一个问题请帮助我我想使用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)”作为参数,但我需要curent click 的值

如果我们从这个生成的脚本中删除双引号,那么它的工作数据:“$(this).attr(id)”,js helper 会生成这个,为什么会被引用

<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;
});

4

2 回答 2

0

Hi Himanshu we had planned to do the same directly using jquery but wanted to do the same via cakephp bind function only. What will be the difference if we pass the js in buffer.

于 2013-10-18T05:39:40.323 回答
0

试试这个。

 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;
 });'
 );
于 2013-10-17T06:51:11.163 回答