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