Using Rails trying to pass in a JSON string from view to JS

Using Rails trying to pass in a JSON string from view to JS

fayette1212fayette1212 Posts: 1Questions: 1Answers: 0
edited November 2016 in Free community support

I was playing around with child rows and have been using a hardcoded json string in my data table

$(document).ready(function() {
var table = $('#queryone_table').DataTable( {
"ajax": "/objects.txt",

I now want to switch to my real code. I have a controller that goes out to mongo and returns a json string, My view has that variable @mongoReturn I am unsure how to pass in that json string from my view to my javascript file that has my datatable definition.

Here is what I tried

My View

<

table class='table table-striped table-bordered table-hover table-condensed' id='queryone_table' data-source=<%= @mongoReturn %>)>

My JS

$(document).ready(function() {
var table = $('#queryone_table').DataTable( {
bServerSide: true,
sAjaxSource: $('#mongoReturn').data('source'),
"columns": [

Answers

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin

    What does your JSON return look like?

    bServerSide: true,

    Does your server-side script actually implement server-side processing? Note also that since you use sAjaxSource it will be sending the legacy parameters.

    Allan

This discussion has been closed.