0

我试图让 ajax 使用 rails 加载 json 变得可动态化,但我收到一个错误,我需要帮助解释。我该如何设置?

安慰

TypeError: 'undefined' is not an object (evaluating 'settings.dataset.records.length')

日志

Started GET "/subjects/index.json?page=1&perPage=10&offset=0" for 127.0.0.1 at 2014-01-25 23:20:47 +0100
Processing by SubjectsController#index as JSON
  Parameters: {"page"=>"1", "perPage"=>"10", "offset"=>"0"}
  Subject Load (3.0ms)  SELECT "subjects".* FROM "subjects"
Completed 200 OK in 3035ms (Views: 0.1ms | ActiveRecord: 3.0ms)
[2014-01-25 23:20:50] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

主题.JS

jQuery(document).ready(function() {
      $('#subjects-table').dynatable({
        table:{
                defaultColumnIdStyle: 'underscore',
        },

      dataset: {
        ajax: true,
        ajaxUrl: '/subjects/index.json',
        ajaxOnLoad: true,
        contentType: "application/json; charset=utf-8",
        records: []

      }

    });
});    

Subjects_controller

class SubjectsController < ApplicationController

    def index
        @subjects = Subject.all
        respond_to do |format|
            format.html
            format.json {render :json => @subjects.to_json}
        end
    end

end
4

1 回答 1

0

看看应该如何处理 AJAX 响应:http ://www.dynatable.com/dynatable-ajax.json 。

于 2014-02-21T11:46:34.197 回答