使用BackBone的POST有效负载传递带有数据值的数组

时间:2016-01-05 12:11:26

标签: javascript php arrays backbone.js

使用BackBone我发送变量和数组以发送调用以发送到数据库。我能够获得变量。但是当我尝试访问数组时,它会转到ERROR并且无法访问该数组。这是发送方式是否正确?

AdminView.php

  addQuestion: function (event) {
    var question = $('#txtQuestion').val();
    var correctAns = $('#txtCorrectAns').val();
    var options = ["Saab", "Volvo", "BMW"];
    var data = {question: question, catID: catID, correctAns: correctAns, options: options};
    Backbone.ajax({
        type: 'POST',
        ansyc: false,
        url: "http://localhost/TEST/index.php/Rest_API/RestAPI/question",
        data: data,
        dataType: 'json',
        success: function (val) {
            alert("Success");
        },
        error: function (erorr) {
            alert("Failed");
        }
    });
}

RESTAPI

function question_post() {
        $question = $this->post('question');
        $catID = $this->post('catID');
        $correctAns = $this->post('correctAns');
        $options = $this->post('options');

        $this->load->model('QuestionModel');
        $response = $this->QuestionModel->addQuestion($question,$catID,$correctAns);
        $this->response($response);
    }

1 个答案:

答案 0 :(得分:0)

使用模型并使用Model.save()

http://backbonejs.org/#Model-save