开发者

RoR : JQuery and Ajax request

I am a fan of Ruby on Rails and currently looking into tutorials about adding AJAX to the page. I tried this tutorial, with the source 开发者_运维知识库also there. I kinda understand the code, but on my computer, after sliding the stock-list does not update and keeps on displaying the entire stock list, but clearly the values are passed around correctly, as I can check it in the controller.

I tried modifying the code and adding JRails in app/views/index.js.erb instead of

respond_to do |format|
  format.html
  format.js do
    render :update do |page|
      page.replace_html 'x_stock_list', :partial => 'stocks/stock_list', :locals => { :stocks => @stocks }
    end

or even adding a simple alert js function into this file, but it shows it as plain text, when i force it to use that file (by deleting the 'format.html' line above). Apparently, the javascript did not get executed.

According to a lot of tutorials by Ryan Bates (RailsCasts) , this line had to be added to application.js:

jQuery.ajaxSetup({  'beforeSend': function(xhr)

{xhr.setRequestHeader("Accept", "text/javascript")}})

to force javascript to get executed, but that did not help either.

Has anybody an idea or is it only on my pc that the slider does not update?


Move your format.html down to the last format in the list. I had this problem a while back and apparently the order matters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜