ruby on rails - Passing JSON data from Controller to JavaScript -
there service when hit it return me json this, think returning me correct json need:
now in client contoller have simple call service , json , if put break points can see yes have same json posted above
class pharmacycontroller < applicationcontroller def index @order_summary = client.get_order_summary(10) gon.data = @order_summary # attempt pass gon gem. end end
and in pharmacy/index.html.erb calling javascript:
<%= javascript_include_tag 'dummy.js' %>
and dummy.js javascript file looks now, make sure can see same number of elements no array:
$( document ).ready(function() { var data = gon.data; console.log( data.length); });
but returns "undefined"
do have other suggestions how achieve this?
use jquery ajax
$.ajax({ url: <url>, type: 'get', data: {}, success: function (data) { console.log( data); } });
Comments
Post a Comment