0

下面的文件在.html.erb中说它需要旧的。

    <%

        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>
4

1 回答 1

1

问题是mash在呈现页面时评估一次,因此一次又一次地使用 erb 总是会产生相同的结果。如果您想要新数据,您可能需要使用 AJAX 请求它。

在 Rails 中,如何使用视图呈现 JSON?

使用 jQuery 进行 ajax 调用的文档:http: //api.jquery.com/jQuery.ajax/

前任:

setInterval(function() { 
  $.get('route/to/mash.json', function(data) {
     onDataReceived(data);
  });
}, 5000);
于 2013-02-02T09:05:24.843 回答