作者:够不李先生 | 来源:互联网 | 2023-09-18 08:38
Iwant,onsuccess,showaninitiallyhiddenalert,andthen,fadeitoutafteranamountofseconds
I want, on success, show an initially hidden alert, and then, fade it out after an amount of seconds.
我想,在成功的时候,显示一个最初隐藏的警报,然后在几秒钟后淡出它。
I don't know why I am not getting this right, which seems pretty simple.
我不知道为什么我做的不好,这看起来很简单。
This is my approach, my PHP:
这是我的方法,我的PHP:
x
Success!
And my Javascript (the AJAX part):
我的Javascript (AJAX部分):
$.ajax({
type: 'POST',
url: 'note.php',
data: { note: note, request_id: request_id, cve: cve, note_id: note_id, status: status,
},
success: function(msg){
$("#success-alert").hide();
$(".add-note").click(function showAlert() {
$("#success-alert").alert();
$("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
$("#success-alert").alert('close');
});
});
}
});
The result is that the alert is not initially hidden, since it is hidden when success.
结果是,警报最初并没有隐藏,因为成功时它是隐藏的。
I have also tried with the hide
class and remove the $("#success-alert").hide();
part.
我还尝试过隐藏类并删除$(“#success-alert”).hide();部分。
I am starting to think this is impossible to achieve, to do this on AJAX success, and I have come up with this other (but worse, because it is not on success) solution.
我开始认为这是不可能实现的,要在AJAX上实现这一点,我已经提出了另一个解决方案(但更糟糕的是,因为它不成功)。
$(document).ready (function(){
$("#success-alert").hide();
$(".add-note").click(function showAlert() {
$("#success-alert").alert();
$("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
$("#success-alert").alert('close');
});
});
});
The result is that it works only the first click, the second click don the button doesn't work, only if I refresh the page.
结果是,它只在第一次点击时起作用,第二次点击don按钮不起作用,只有当我刷新页面时。
The other solution I have tried, is to divide the code into:
我尝试过的另一个解决方案是将代码分为:
$(document).ready (function(){
$("#success-alert").hide();
});
$(".add-note").click(function showAlert() {
$("#success-alert").alert();
$("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
$("#success-alert").alert('close');
});
});
The result is that I that the alert appears for an instant and disappears instantly.
结果是,警报出现了片刻,立即消失。
How can I solve this, apparently easy problem¿? Thank you very much.
我怎么才能解决这个问题呢?非常感谢。
2 个解决方案