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

Pass array with data values using POST payload with BackBone

本文关键字:数据 数组 BackBone POST 有效 负载 使用      更新时间:2023-09-26

使用BackBone,我将变量和数组都发送到post调用,以发送到数据库。我能够获得变量。但当我尝试访问数组时,它会出现错误,也无法访问该数组。这种发送方式正确吗?

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);
    }

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

http://backbonejs.org/#Model-保存