0
我有一个关于javascript和cakephp的问题,我需要通过Post发送数据,并在另一端(控制器)中收回数据,并使我已有的正常进程。但我不知道如何捕捉数据。我与阿贾克斯在控制器中捕获数据
工作function editFun(clicked_id){
var id = clicked_id;
$("#Content").empty();
$('#Content').html("<b>Loading response...</b>");
$.ajax({
type: 'POST',
url: '/Posts/edit',
data: (id)
})
.done(function(data){
console.log(data);
$('#Content').html(data);
})
.fail(function(data){
$('#Content').html(data);
});
}
public function edit($id = null) {
\t \t \t \t if (!$id) {
\t \t \t \t \t throw new NotFoundException(__('Invalid post'));
\t \t \t \t }
\t \t \t \t $post = $this->Post->findById($id);
\t \t \t \t if (!$post) {
\t \t \t \t \t throw new NotFoundException(__('Invalid post'));
\t \t \t \t }
\t \t \t \t if ($this->request->is(array('post', 'put'))) {
\t \t \t \t \t $this->Post->id = $id;
\t \t \t \t \t if ($this->Post->save($this->request->data)) {
\t \t \t \t \t \t $this->Session->setFlash(__('Your post has been updated.'));
\t \t \t \t \t \t return $this->redirect(array('action' => 'index'));
\t \t \t \t \t }
\t \t \t \t \t $this->Session->setFlash(__('Unable to update your post.'));
\t \t \t \t }
\t \t \t \t if (!$this->request->data) {
\t \t \t \t \t $this->request->data = $post;
\t \t \t \t }
\t \t \t }
当通过Ajax调用,数据不会发送的正常方式。我不记得哪个变量你可以期望找到数据,所以请检查'$ this-> request'和'$ this-> params-> query'。 – Kai 2014-10-17 19:36:30