0

我正在尝试 ajax 更新数据库中的记录。这是我的代码。我通过将 $this->request->data 写入日志来进行测试,但它只是空白。关于我做错了什么的任何想法?

$.ajax({
    type: "POST",
    url: "http://localhost:8888/cake/tasks/updateStatus",
    data: {id: $(this).attr("id"), status: "checked"}, 
    contentType: "application/json",
    success: function(response, status) {
        alert ("Success");
    },
    error: function(response, status) {
        alert('Error! response=' + response + " status=" + status);
    }
});


/* controller */ 

public function updateStatus() {
     $data = json_decode($this->request->data);
     $this->Task->id = $data['id'];
     $this->Task->saveField("status",$data['status']);
}
4

0 回答 0