我正在尝试ajax更新数据库中的记录。这是我的代码。我通过将$ this-> request->数据写入日志来测试,但它只是空白。关于我做错了什么想法?
$.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']);
}