如何使用 Cake PHP js helper 发送 $(this).atta('id')
how to send $(this).atta('id') using cake php js helper
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,会有什么区别。
相关文章:
- $(this).prop('property') vs. this.property
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 在另一个函数中使用变量this
- this.router在AngularJS 2中未定义
- reactjs this.refs vs document.getElementById
- JavaScript 中的嵌套函数和 “this” 关键字
- React+Meteor:this.ops返回未定义
- javascript中对象构造函数中的var属性与this.properties
- 函数中this和var之间的区别
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- Understanding Javascript scope with "var that = this&qu
- 定义this.properties或objectName.properties的javascript JSON对象
- Object.prototype using 'this'
- 在JavaScript类型的函数中避免self-this
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- Javascript 对象和 this 关键字
- jQuery使用ajax自动完成问题-TypeError:this.source不是函数
- reactjs无法将this.pops传递到react图表列表中
- 为什么在这种情况下,“This”确实充当javascript函数中的私有成员
- 如何使用 Cake PHP js helper 发送 $(this).atta('id')