2016-11-30 61 views
0

我的代码工作时间后,但我想说明的时间周期警报(警报警报预警)(警报警报的成功)我也想展示警告一段时间,但在此之后重新加载页面。警报显示和消失的时间

屏幕下面的例子为(警报警报预警) enter image description here

它的工作,但是这将是巨大的,如果警报预警秀了一段时间后消失(我想3秒应该很好)。

屏幕下方为(警报警报的成功) enter image description here

它还工作,我也想展示并在一段时间后消失,但该警报我的警报后要消失它的直接重新载入页面(不关闭X按钮)

这是我的index.php

enter image description here

这是我register.php

enter image description here

,这是我main.js

enter image description here

我的问题是在main.js,我尝试了一些代码,它的工作,但警报消失后(3秒),当用户尝试再次显示它时,它不再有效。 任何意见,将不胜感激。

+0

邮编为文本 – 2016-11-30 06:05:48

+0

您可以使用sweetalert插件http://t4t5.github.io/sweetalert/这一点。 –

+0

@Chonchol Mahmud,谢谢,插件很好。但我仍然想知道解决我所问的问题。 :) –

回答

1

它没有显示,因为成功回调后,你在setTimeout的3秒后隐藏元素。你需要做的是,在运行前setTimeout功能,只显示元件回类似的例子页:

success : function() { 
    $('#register_message').show(); //show the element back 
    $('#register_message').html(''); // remove existing element 
    $('#register_message').html(data); // adding new element coming from server side 
    ........... 
    the rest of the code 
    .......... 

} 

对于重载:

如果从服务器端传来的数据是HTML代码,那么这样做:

success : function (data) { 

    $('#register_message').show(); //show the element back 
    $('#register_message').html(''); // remove existing element 
    $('#register_message').html(data); // adding new element coming from server side 

    setTimeout(function() { 
     $('#register_message').hide(); 
     // and at here you can check whether the html coming is success or error 
     if ($(data).hasClass('alert-success')) 
      location.reload(); 

    }, 3000); 

} 
+0

嗨,感谢您的帮助,但我仍然有1个问题需要您的建议。错误和成功的消息在3秒钟后消失,为了成功,我如何将它包括在3秒后直接重新加载? 如果我在代码下面添加重新加载,它的工作,但对于错误消息,它也将重新加载页面后显示警报,应该显示警报和消失,我如何设置错误信息显示警报和消失。成功显示警报然后消失,然后重新加载页面。任何建议? –

+0

很高兴听到这个,你不受欢迎的队友 –

0

试试这个:

setTimeout(function() { alert("my message"); }, time); 

代替JS警报(),你可以调用自举模式的警报或jQuery UI的对话框类似警告。