在提交多个表单(在Rails中)后,试图在显示Ajax之后再次显示JQuery Flash消息

在提交多个表单(在Rails中)后,试图在显示Ajax之后再次显示JQuery Flash消息

问题描述:

我有一个表单,可以简单地通过ajax添加新的密钥名称.我希望用户每次添加新键(而不是从弹出框)时都显示一条消息.我使用的是Ruby on Rails,因此,当数据成功添加到数据库时,将执行以下Jquery编码.

I have a form that simply adds a new key name through ajax. I want a message to show every time the user adds a new key (not from a popup box). I'm using Ruby on rails so the Jquery coding below is executed when the data is successfully added to the db.

这是在提交Ajax之后运行的JQuery编码.

This is the JQuery coding that runs after an ajax from submit.

$('#status-area').html("");

$('#status-area').append("key added successfully");

$('#status-area').fadeOut(3000);

这是div

  <div id="status-area"></div>

它的工作原理就像我想要的第一次提交一样.只需删除div中的所有先前文本,然后说密钥添加成功",然后淡出即可.问题是,如果我再次提交表单,则会添加新的密钥,但是消息不会再次显示.

It works Just like I want for the first submit. Simply removing any previous text in the div and saying 'Key added successfully' then fading out. Problem is if I submit the form again a new key is added but the message doesn't show again.

它应该在第二次提交时再次执行此编码,删除旧文本并重新附加消息,但不会.

It should run through this coding again on the second submission removing the old text and re appending the message but it doesn't.

为什么它不再显示?

这是正常行为,因为fadeOut将设置display: none

It's normal behaviour because fadeOut will set the display: none

所以您将不得不使用

$('#status-area').fadeIn();

$('#status-area').html("");

$('#status-area').append("key added successfully");

$('#status-area').fadeOut(3000);