[英]I want to make the success notification and error notification fade after 4 seconds after the notification but have tried doing it not working.
$( document ).ready(function() {
$("#ajaxform").submit(function(e){
var contactdata = $(this).serializeArray();
var submiturl = $(this).attr('action');
var submitbtn = $('#submit');
submitbtn.val('Sending...');
$("#ajaxform :input").prop("disabled", true);
$.ajax({
url: submiturl,
type: 'POST',
dataType: "json",
data : contactdata,
success: function(response){
$('#alert').removeClass('alert alert-success');
$('#alert').removeClass('alert alert-danger');
if(response.status=="true"){
$('#alert').addClass('alert alert-success');
$("#ajaxform :input").prop("disabled", false);
$('#ajaxform')[0].reset();
submitbtn.val('Send');
}else{
$("#alert").addClass('alert alert-danger');
$("#ajaxform :input").prop("disabled", false);
submitbtn.val('Send');
}
$('#alert').html(response.message).slideDown();
}
});
e.preventDefault();
});
});
I want to make the success notification and error notification fade after 4 seconds after the notification but have tried doing it not working. 我想使成功通知和错误通知在通知后4秒钟后消失,但是尝试不起作用。 Am new in coding javascript
JavaScript编码新手
This part shows the alert: 此部分显示警报:
$('#alert').html(response.message).slideDown();
The code hiding the alert after 4 seconds is missing. 4秒后隐藏警报的代码丢失。 You would put it after the code showing the alert.
您可以将其放在显示警报的代码之后。 For example:
例如:
setTimeout(function() { $('#alert').hide(); }, 4000);
Link to documentation: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout 链接到文档: https : //developer.mozilla.org/zh-CN/docs/Web/API/WindowTimers/setTimeout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.