Jquery 如何在页面重定向上显示jgrowl消息
我已经设置了jgrowl,一切似乎都正常工作。我目前必须按下一个按钮,以触发消息出现在屏幕右上方,如下所示:Jquery 如何在页面重定向上显示jgrowl消息,jquery,ruby-on-rails-3,jgrowl,Jquery,Ruby On Rails 3,Jgrowl,我已经设置了jgrowl,一切似乎都正常工作。我目前必须按下一个按钮,以触发消息出现在屏幕右上方,如下所示: <input type="button" onclick="$.jGrowl('Your transaction has been processed', { life: 10000 });" href="javascript:void(0);" value="Default"/> def ch_sum_total #....some processing stuf
<input type="button" onclick="$.jGrowl('Your transaction has been processed', { life: 10000 });" href="javascript:void(0);" value="Default"/>
def ch_sum_total
#....some processing stuff code....
flash[:notice] = 'Your transaction has been processed'
respond_to do |format|
format.html { redirect_to(:back) }
format.js {}
end
end
我该怎么做 通过传递函数来使用jQuery的处理程序
$(function() {
$.jGrowl('Your transaction has been processed', { life: 10000});
});
这将阻止您的代码执行,直到加载DOM并正确显示jGrowl。我会在控制器上的操作中添加您想要咆哮的消息,以便您可以查看是否必须显示jGrowl 比如说:
<input type="button" onclick="$.jGrowl('Your transaction has been processed', { life: 10000 });" href="javascript:void(0);" value="Default"/>
def ch_sum_total
#....some processing stuff code....
flash[:notice] = 'Your transaction has been processed'
respond_to do |format|
format.html { redirect_to(:back) }
format.js {}
end
end
在:back
页面上,您可以看到如下内容:
<script>
$(function() {
<% if flash[:notice] %>
$.jGrowl('<%= escape_javascript(flash.discard(:notice)) %>', { life: 10000});
<% end %>
});
</script>
$(函数(){
$.jGrowl('',{life:10000});
});
谢谢,不过每个页面都会弹出消息,我只需要在rails中重定向后弹出jgrowl。对不起,我还在学习jquery。你能再解释一下吗。再次感谢您的帮助。这绝对是更“railsy”的方法。@Manuel感谢它在+1中工作得非常好,我想我会学习jquery,因为它的特性非常棒,非常受欢迎。