簡體   English   中英

cakephp骨干保存無法正常工作

[英]cakephp backbone save not working

我有一個用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);
}

我該如何解決?

嘗試將模型中的url更改為urlRoot

TaskModel = Backbone.Model.extend({
    urlRoot: '/step_task/ajax_save'
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM