1

In my rails 3 application, I have a page which needs to periodically check with the server for updated information and then update an unordered list accordingly. Following the example shown at Rails 3 equivalent for periodically_call_remote, I converted into the appropriate CoffeeScript and created the necessary .js.erb partial.

The page calls the server and the server responds with the correct js file, but nothing on the page can be modified. alert('foo'); works fine, but anything on the order of .html() or .replaceWith() will not.

Here's my CoffeeScript:

$(document).ready ->
    setInterval () ->
        $.ajax url: "programs", type: "GET", dataType: "script"
    , 10000

and the corresponding .js.erb:

$("#programlist").html("<%= escape_javascript(render @programs) %>");

Is something wrong here?

Community
  • 1
  • 1
John Wells
  • 1,139
  • 1
  • 10
  • 27

2 Answers2

2

try $("#programlist").load(..);

Jubin Thomas
  • 1,003
  • 2
  • 12
  • 24
0

That mean there is an error in the response (javascript). may be you are using the wrong id here $("#programlist").html(..);

Use firebug addon in firefox to see the response in its console and use it to apply the lines one by one, and see which line has the error.

Good luck :)

Moamen
  • 706
  • 7
  • 19
  • Thanks for replying! Unfortunately, this doesn't seem to be the problem. The response is correct, showing the expected javascript. – John Wells Sep 05 '12 at 09:00
  • Just dummy but may help! try j method instead of escape_javascript! http://apidock.com/rails/ActionView/Helpers/JavaScriptHelper/escape_javascript – Moamen Sep 05 '12 at 09:31