【发布时间】:2014-12-23 02:37:00
【问题描述】:
我尝试使用来自 jquery 的 $.get 发送自定义数据,但 cakephp 3 无法识别变量。
这是我在控制器中的功能:
public function view($cat,$id,$page){
$comments = $this->Comments->find('all')->where(['category =' => $cat, 'AND' => ['category_id =' => $id]])->order(['comments.created' => 'DESC'])
->contain([
'Reports' => function($q){return $q->where(['user_id =' => $this->Auth->user('id')]);},
'Chars' => function($q){ return $q->select(['id','name','class','race','level','guild_id', 'user_id'])
->contain(['Guilds' => function($q){ return $q->select(['id','name']);
}]);
}])->limit(3)->page($page);
if($cat == 'Videos'){
$subject = $this->Comments->Videos->get($id);
}
$category = $cat;
$this->set(compact('subject','comments','category'));
}
}
这是.js
$('.more').click(function(){
$.get($(this).attr('href'),{cat:'Videos',id:'44',page:'2',function(data){
$('.coms').empty().append(data);
});
return false;
});
还有链接:
<?= $this->Html->link('More', ['controller' => 'Comments','action' => 'view'], ['class' => 'btn btn-primary more']) ?>
.js 中的修复值用于测试,如果我使用 $.get(href) 在链接中发送数据,它可以工作,但我想知道如何在 $.get 请求中传递自定义数据。
感谢您的帮助
【问题讨论】:
标签: json ajax cakephp-3.0