error in query.da when loading Ajax jSON : Uncaught TypeError: Converting circular structure to JSON

error in query.da when loading Ajax jSON : Uncaught TypeError: Converting circular structure to JSON

idealcomsidealcoms Posts: 10Questions: 5Answers: 1

I am trying read data from a Rails back-end server using Ajax object loading...

mt table is defined simply as :

$('#groups').DataTable( {
language: { url: langUrl },
dom: 'Bftlp',
ajax: {
dataType: 'json',
type: "GET",
url: "http://" + window.location.host + "/groups",
dataSrc: 'data'
},
//retrieve: true,
info: false,
select: true,
columns: [
{ data: "id" },
{ data: "company_id" },
{ data: "name" },
{ data: "created_at" },
{ data: "updated_at" }
],
...

&nd my server is returning a JSOn structure

 # GET /groups
def index
  @groups = policy_scope(Group) 
  respond_to do |format|
    format.html
    format.json { 
      @rows = []
      for group in @groups do
        @rows << group.attributes
      end
      @data = {data: @rows}
      render json: @data.to_json
    }
  end
end

the data returned seems to be correctly set :

{data: @rows}.to_json
{"data":
[
{"id":1,"company_id":1,"created_at":"2015-10-27T18:38:18.729+01:00","updated_at":"2015-10-27T18:38:18.746+01:00","name":"système"},
{"id":3,"company_id":1,"created_at":"2015-10-27T18:38:18.783+01:00","updated_at":"2015-10-27T18:38:18.812+01:00","name":"marketing"},
{"id":4,"company_id":1,"created_at":"2015-10-27T18:38:18.796+01:00","updated_at":"2015-10-27T18:38:18.819+01:00","name":"comptabilité"},
{"id":2,"company_id":1,"created_at":"2015-10-27T18:38:18.768+01:00","updated_at":"2015-11-02T19:10:54.179+01:00","name":"administration"},
{"id":61,"company_id":1,"created_at":"2015-11-01T11:49:40.752+01:00","updated_at":"2015-11-01T11:49:40.848+01:00","name":"juridique"}
]
}

The euro is raised in the jsquery.dataTables.js ,when trying to log the settings.... ( setting: is displayed in the log)

      console.log("settings: ");
      console.log(JSON.stringify(settings, null, 2));

what's wrong with my ajax setting ?

thanks for feedback

This question has an accepted answers - jump to answer

Answers

  • idealcomsidealcoms Posts: 10Questions: 5Answers: 1
    edited November 2015 Answer ✓

    seems o be a BUG... in query.dataTables.js commenting out this line and the ajax request is perfect .... but a bug on my side ... I added it few weeks ago and forgot it ..

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Yes, stringifying the settings object would be bad news! It does indeed contain circular references and DOM nodes.

    Allan

This discussion has been closed.