0

Below file is in .html.erb i want to call mash again and again how i do it.I tried many times through setInterval but it getting old value of data.I am getting new value in mesh data.but when i see second time calling it takes old.

    <%

        mash = {
          "id" => id, "legends" => legends, "x_units" => x_units, "y_units" => y_units, "data" => data, "alertPoints" => alert_points, "time_mode" => time_mode, 
          "colors" => colors, "x_label" => x_label, "y_label" => y_label, "tipColors" => tipColors, "dateformat" => @dateformat, "timeformat" => @timeformat, 
          "chart_url" => chart_url, "x_label_date_format" => x_label_date_format, "turn_series" => turn_series, "y_ticks_array" => y_ticks_array, "y_label_width" => y_label_width,
          "series_type" => series_type,"vertical_threshold" => vertical_threshold, "x_label_suffix" => x_label_suffix, "y_tick_on" => y_tick_on, "xmin" => xmin, "xmax" => xmax
          }
        %>


            <script type="javascript">

                  setInterval(    function ()
                 {
                 onDataReceived(<%=mash.to_json.html_safe%>);



                 }, 5000);
              </script>
2
  • how are you fetching your data? What's your ajax callback like? Kinda hard to tell whats wrong without anymore details... Commented Feb 2, 2013 at 6:26
  • if use put command to see mash[data] it dynamically change.but <%=mash.to_json.html_safe%> it getting old value .can i call above mash again and again Commented Feb 2, 2013 at 6:40

1 Answer 1

1

The issue is that mash is evaluated once when the page is rendered, so using the erb again and again will always produce the same result. If you want new data, you probably need to request it with AJAX.

In Rails, how do you render JSON using a view?

Docs to make ajax calls with jQuery: http://api.jquery.com/jQuery.ajax/

Ex:

setInterval(function() { 
  $.get('route/to/mash.json', function(data) {
     onDataReceived(data);
  });
}, 5000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.