Javascript 在控制器中捕获数据
我有一个关于javascript和cakephp的问题,我需要通过Post发送数据,并在控制器的另一端接收数据,并完成我已经完成的正常过程。但我不知道怎样才能捕捉到数据。我在用Ajax 函数editFunclicked\u id{ var id=单击的\u id; $Content.empty; $'Content'.htmlLoading响应。。。; $.ajax{ 键入:“POST”, url:“/Posts/edit”, 数据:id } .donefunctiondata{ 控制台日志数据; $'Content'.htmldata; } .failfunctiondata{ $'Content'.htmldata; }; } 公共函数edit$id=null{ 如果!$id{ 抛出新的NotFoundException_uu'Invalid post'; } $post=$this->post->findById$id; 如果!$post{ 抛出新的NotFoundException_uu'Invalid post'; } 如果$this->request->isarray'post',put'{ $this->Post->id=$id; 如果$this->Post->save$this->request->data{ $this->Session->setFlash_uu_u“您的帖子已更新”; 返回$this->redirectarray'action'=>'index'; } $this->Session->setFlash\uuuuu“无法更新您的帖子”; } 如果!$this->request->data{ $this->request->data=$post; }Javascript 在控制器中捕获数据,javascript,php,ajax,cakephp,Javascript,Php,Ajax,Cakephp,我有一个关于javascript和cakephp的问题,我需要通过Post发送数据,并在控制器的另一端接收数据,并完成我已经完成的正常过程。但我不知道怎样才能捕捉到数据。我在用Ajax 函数editFunclicked\u id{ var id=单击的\u id; $Content.empty; $'Content'.htmlLoading响应。。。; $.ajax{ 键入:“POST”, url:“/Posts/edit”, 数据:id } .donefunctiondata{ 控制台日志数
} 在这种情况下,您应该在URL中发送您的id。所以,即使GET方法也足够了,因为您可以从URL接收$id参数 因此,所有需要更改的都是post参数:
$.ajax({
type: 'POST',
url: '/Posts/edit/' + id
})
通过Ajax调用时,数据不会以正常方式发送。我不太记得您希望在哪个变量中找到数据,所以请检查$this->request和$this->params->query。非常感谢,这就是答案!!