我有一个简单的AJAX请求,它根据表中的某些选择更新一些PHP会话变量。如果AJAX请求发生错误,我会更改它们所选表格的颜色(如果它们选择“是”,则通常会变为绿色,如果选择“否”,则会变为红色)。这一切都很好。在AJAX请求错误中显示引导警报
我现在想在屏幕上显示的可取消引导警报之一,也是一样,在他们的例子:
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<strong>Warning!</strong> Better check yourself, you're not looking too good.
</div>
,但我不知道我怎么会引起这会在AJAX请求发生错误时显示。这里是我的脚本:
$(document).ready(function() {
$('button.btn-success').click(function() {
var refreshItemID = $(this).closest('tr').attr('id');
console.log(refreshItemID);
// Create a reference to $(this) here:
$this = $(this);
$.post('updateSelections.php', {
refreshItemID: refreshItemID,
selectionType: 'yes'
}, function(data) {
data = JSON.parse(data);
if (data.error) {
console.log(data);
console.log('something was wrong with the ajax request');
$this.closest('tr').addClass("warning");
return; // stop executing this function any further
} else {
console.log('update successful - success add class to table row');
$this.closest('tr').addClass("success");
$this.closest('tr').removeClass("danger");
//$(this).closest('tr').attr('class','success');
}
}).fail(function(xhr) {
console.log('ajax request failed');
// no data available in this context
$this.closest('tr').addClass("warning");
});
});
});
你可以看到它增加了一个警告类的表行,如果有一个错误:
$this.closest('tr').addClass("warning");
,但我不知道如何扩展这也添加了一个可以接受的警报(以及如何控制该警报的位置)?
使用这种自举通知[点击此处](http://bootstrap-notify.remabledesigns.com/) –