我的ajax
样子
// send the data to the server using .ajax() or .post()
$.ajax({
type: 'POST',
url: 'addVideo',
data: {
video_title: title,
playlist_name: playlist,
url: id
// csrfmiddlewaretoken: '{{ csrf_token }}',
},
done: notify('success', 'video saved successfully'),
fail: notify('error', 'There were some errors while saving the video. Please try in a while')
});
notify
好像
function notify(notify_type, msg) {
var alerts = $('#alerts');
alerts.addClass('alert');
alerts.append('<a class="close" data-dismiss="alert" href="#">×</a>');
if (notify_type == 'success') {
alerts.addClass('alerts-success').append(msg).fadeIn('fast');
}
if (notify_type == 'failure') {
alerts.addClass('alerts-error').append(msg).fadeIn('fast');
}
}
- 当我保存单击按钮时,我收到成功消息
视频保存成功 x(叉号)
- 我点击交叉,现在通知消失了
当我再次保存单击按钮时,没有任何反应,我看到萤火虫在抱怨
No elements were found with the selector: "#alerts"
我的猜测是单击十字标记会
div="alerts"
完全从 DOM 中删除标记。这是正确的吗?
问题 - 我怎样才能得到正确的行为。单击十字标记删除通知 div,单击按钮创建再次创建通知 div