テーブル内のいくつかの選択に基づいてPHPセッション変数を更新する単純なAJAXリクエストがあります。 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>
が、私は私が発生する可能性がありますかわからない:
私は今、彼らの例のように、だけでなく、画面上のdismissibleブートストラップアラートのいずれかを表示したいと思いますこれは、AJAXリクエストにエラーがあるときに表示されます。
$this.closest('tr').addClass("warning");
が、私は拡張するかどうかはわかりません:そこのエラーかどう
$(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");
});
});
});
あなたはそれを見ることができますが、テーブルの行への警告クラスを追加します。ここに私のスクリプトですこれはまた、棄却可能なアラートを追加する(そしてそのアラートの位置を制御する方法)?
使用このブートストラップは、通知[こちらをクリック](http://bootstrap-notify.remabledesigns.com/) –