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:

enter image description here

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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -