我有一個網站在cakephp開發,我在骨幹中使用一個簡單的應用程序。 現在我想從骨幹保存數據,但不起作用,總是返回內部回調錯誤,並沒有採取正確的值來保存表內。cakephp骨幹保存不工作
這是我的簡單的應用程序:
TaskModel = Backbone.Model.extend({
url: function(){
return "/step_task/ajax_save";
}
});
TaskCollection = Backbone.Collection.extend({
model: TaskModel,
initData: function(data){
return data;
}
});
var TaskView = Backbone.View.extend({
template: _.template($("#task-template").html()),
initialize: function(){
this.task = new TaskCollection(<?php echo json_encode($step['StepTask']); ?>);
this.render();
},
render: function(){
taskModel = new TaskModel({
'id': '1',
'user_id': '1'
});
//--------------------------- here I would like to save inside my table ----------------
taskModel.save(null, {
success: function(model, response) {
console.log('success');
console.log(model);
console.log(response);
},
error: function(model, response) {
console.log('error');
console.log(model);
console.log(response);
},
wait: true // Add this
});
$(this.el).html(this.template({tasks: this.task.models}));
}
});
,這是我的內StepTaskController.php
public function ajax_save(){
$this->autoRender = false;
$this->StepTask->save($this->request->data);
}
功能可按我該如何解決呢?
有什麼錯誤訊息? – linstantnoodles
在控制檯中沒有錯誤,但在回調錯誤內返回並且它沒有正確的值來保存 –
響應中的HTTP狀態是什麼?它看起來並不像你在迴應任何事情。嘗試使用json進行響應。看到這[後](http://stackoverflow.com/questions/1226330/how-to-return-the-correct-content-type-for-json-in-cakephp)。 – linstantnoodles