Ruby on Rails上的AJAX/Javascript错误
好的,这就是我现在的位置。我有三个不同的东西在这里,我非常接近让它工作 我有一个checkbox=值为1的表单,它收集“post”的“投票”,并将其发送到带有post_id的数据库。这非常有效 我有一个部分模板,可以将特定的投票返回表单下方 我已经设置了AJAX,以便在提交投票时将其显示在@post.vows上 数据库正在接收投票,分部正在显示它们,但是当javascripts运行时,我得到以下错误:Ruby on Rails上的AJAX/Javascript错误,javascript,ruby-on-rails,ruby,ajax,Javascript,Ruby On Rails,Ruby,Ajax,好的,这就是我现在的位置。我有三个不同的东西在这里,我非常接近让它工作 我有一个checkbox=值为1的表单,它收集“post”的“投票”,并将其发送到带有post_id的数据库。这非常有效 我有一个部分模板,可以将特定的投票返回表单下方 我已经设置了AJAX,以便在提交投票时将其显示在@post.vows上 数据库正在接收投票,分部正在显示它们,但是当javascripts运行时,我得到以下错误: RJS error: TypeError: Result of expression '((
RJS error:
TypeError: Result of expression '((position == 'before' || position == 'after')
? element.parentNode : element)' [null] is not an object.
然后:
Element.insert("votes", { top: "<div class=\"vote\" id=\"vote_44\">\n\n\n\t\t1\n\n\n\n\t\n\t\n\t</div>\n\t\n" });
$("vote_44").visualEffect("highlight");
$("vote").reset();
最后是我的/layouts/posts.html.erb文件,我认为错误不在这里,因为AJAX注释可以与这个包装器配合使用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Posts: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<% auto_discovery_link_tag :atom, formatted_posts_path(:atom) %>
<%= javascript_include_tag :all %>
<script type="text/javascript">
function toggleLayer( whichLayer )
{
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
</script>
</head>
<body>
<div id="stage">
<div id="leftbar">
</div>
<div id="middlebar">
<div id="topmiddle">
</div>
<div id="middlecontent">
<div id="middlecontenttext">
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</div>
</div>
</div>
<div id="rightbar">
<div id="rightbarband">
<p5>Most<br/>Commented<br/>Battlecries</p5>
<p>This is where these will go.</p><br/><br/>
<p5>Search BattleCries</p5>
<input = "submit"><br/>
<br/><br/>
<p5>Get the Wristband</p5>
<img src="../images/wristband.png" width="208" height="79" alt="Wristband">
<p>Tell us the title of your Life BattleCry and we will print it on a reminder wristband. Click here and be done in 60 seconds.</p>
<br/><br/>
<p5>Get the <br/>T-Shirt</p5>
<img src="../images/logoshirt.png" width="208" height="42" alt="Logoshirt">
<p>this is where an image and also some very interesting text about the sweet wristband will go</p>
<br/><br/>
<p></p>
</div>
</div>
</div>
</body>
</html>
帖子:
功能切换层(whichLayer)
{
var-elem,vis;
if(document.getElementById)//这是标准的工作方式
elem=document.getElementById(whichLayer);
else if(document.all)//这是旧msie版本的工作方式
elem=文档.all[whichLayer];
else if(document.layers)//这是nn4的工作方式
elem=document.layers[whichLayer];
vis=元素样式;
//如果style.display值为空,我们将在此处尝试计算它
如果(可视显示=''&&elem.offsetWidth!=未定义&&elem.offsetWidth!=未定义)
vis.display=(elem.offsetWidth!=0&&elem.offsetHeight!=0)?“块”:“无”;
vis.display=(vis.display=“”| | vis.display=='block')?'none':'block';
}
大多数人都发表了评论
这就是它们要去的地方。
搜索战斗口号
去拿腕带
告诉我们你的人生呐喊的标题,我们会把它印在提醒腕带上。单击此处并在60秒内完成
买一件
T恤
这是一张关于这款甜美腕带的图片和一些非常有趣的文字
在RJS模板(/vots/create.js.RJS
)中,您有一行:
page.insert_html :top, :votes, :partial => @vote
我认为您可能需要在/posts/show.html.erb
中使用一个带有id='vows'
的DIV,以便javascript知道在何处插入此html
insert_html
的文档是您能否识别错误消息中引用的代码段(((position='before'| | position='after')?element.parentNode:element)出现的位置?你在这里发布的任何示例中似乎都没有。很抱歉,我想它出现在浏览器的弹出窗口中。如果可以的话,我会用一个屏幕截图来更新这个问题。从功能的角度来看,这个问题是有效的,但是我现在遇到了这个错误。错误的相同浏览器表示形式:TypeError:表达式“$(“投票”)的结果“[null]不是对象。元素。插入(“投票”{top:\n\t\t0\t\n\t\n\t\n})$(“投票50”)。视觉效果(“突出显示”)$(“投票”).reset();有什么想法吗?这是两个不同的错误,只是没有在评论中格式化,第一个以…object结尾。只是修复了它。去掉了页面[:vote]。在create.js.rjs中重置,它就可以工作了。奇怪,很高兴你把它整理好了。显示错误的警报框是由rails引起的,这就是RJS错误在开发模式下运行时的显示方式。在config/development.rb中,您将看到行“config.action\u view.debug\u rjs=true”。这就是控制这些错误显示的原因。您的RJ将在生产模式下无声地发生故障。不管怎样,很高兴听到你明白了。
<% div_for vote do %>
<%= h(vote.vote) %>
<% end %>
page.insert_html :top, :votes, :partial => @vote
page[@vote].visual_effect :highlight
page[:vote].reset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Posts: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<% auto_discovery_link_tag :atom, formatted_posts_path(:atom) %>
<%= javascript_include_tag :all %>
<script type="text/javascript">
function toggleLayer( whichLayer )
{
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
</script>
</head>
<body>
<div id="stage">
<div id="leftbar">
</div>
<div id="middlebar">
<div id="topmiddle">
</div>
<div id="middlecontent">
<div id="middlecontenttext">
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</div>
</div>
</div>
<div id="rightbar">
<div id="rightbarband">
<p5>Most<br/>Commented<br/>Battlecries</p5>
<p>This is where these will go.</p><br/><br/>
<p5>Search BattleCries</p5>
<input = "submit"><br/>
<br/><br/>
<p5>Get the Wristband</p5>
<img src="../images/wristband.png" width="208" height="79" alt="Wristband">
<p>Tell us the title of your Life BattleCry and we will print it on a reminder wristband. Click here and be done in 60 seconds.</p>
<br/><br/>
<p5>Get the <br/>T-Shirt</p5>
<img src="../images/logoshirt.png" width="208" height="42" alt="Logoshirt">
<p>this is where an image and also some very interesting text about the sweet wristband will go</p>
<br/><br/>
<p></p>
</div>
</div>
</div>
</body>
</html>
page.insert_html :top, :votes, :partial => @vote