如何解决Rails中无提示失败的JS

如何解决Rails中无提示失败的JS

本文介绍了如何解决Rails中无提示失败的JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该注意,我对Firebug的使用不是很熟练,但是我没有发现任何错误可以解释以下问题.

It should be noted that I am not very proficient at using Firebug, but I haven't found any errors that explain the following issue.

我有一个feed.js.erb文件,其中包含以下代码:

I have a feed.js.erb file containing the following code:

var $foos = $('<%= escape_javascript(render(@foos)) %>');
$('#container').append($foos);
$('#pagination_button a').attr('href', '<%= feed_path + '?page=' + @page %>');

当第二次进行此Ajax调用 时,它似乎无声地失败了.我在Firebug控制台中看到了适当的响应,但是 $foos未被更改,并且随后从未附加#container.

When this ajax call is made the second time, it appears to fail silently. I see the appropriate response in the Firebug console, but $foos is not altered and subsequently the #container is never appended.

我的html页面仅包含一个加载指示器,该指示器在第一次调用时已成功替换.第二个调用是从其他javascript( Infinite Scroll )触发的.

My html page only includes a loading indicator, which it successfully replaces on the first call. The second call is triggered from other javascript (Infinite Scroll).

如果有关系,我注意到第一个调用是使用自动生成的timestamp参数进行的.之后,如您在#pagination_button a上看到的那样,我将替换目标URL.

If it matters, I have noticed that the first call is made with an automatically generated timestamp parameter. After that I am replacing the target url as you can see on my #pagination_button a.

如何在浏览器中调试它?

How can I debug this in the browser?

更新 :我使用ERB将$foos设为动态变量($ foos1 ... $ foos2),并注意到这也不起作用.因此,即使新的@foos在控制台的响应中可见,我的javascript的第一行也没有得到评估.

Update: I used ERB to make $foos a dynamic variable ($foos1...$foos2) and noticed that this is also not working. So even though the new @foos are visible in the console's response, the first line of my javascript is not being evaluated.

推荐答案

事实证明,Rails并未将我的第二个请求作为JS处理.更重要的是,如果JS引发异常,它将被转换为纯文本如此处所述. 史蒂夫还展示了如何调试ajax代码,有效地回答了我的两个问题.

As it turns out, Rails is not processing my second request as JS. More importantly, if the JS raises an exception, it will be converted to plain-text as explained here. Steve also shows how to debug ajax code, effectively answering both of my questions.

这篇关于如何解决Rails中无提示失败的JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:13