Tôi có một cuộc gọi ajax
nhưjQuery: chạy ajax cả xử lý - làm và thất bại
$.ajax({
type: 'POST',
url: 'addVideo',
data: {
video_title: title,
playlist_name: playlist,
url: id
// csrfmiddlewaretoken: '{{ csrf_token }}',
},
done: bootstrap_alert.success('video saved successfully'),
fail: bootstrap_alert.error('There were some errors while saving the video. Please try in a while')
});
và hành động như
// setting up alerts on action
bootstrap_alert = function() {}
bootstrap_alert.success = function(message) {
$('#feature').prepend('<div class="alert alert-success"><a class="close" data-dismiss="alert">×</a><span>'+message+'</span></div>');
}
bootstrap_alert.error = function(message) {
$('#feature').prepend('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><span>'+message+'</span></div>');
}
Khi kết thúc trước làm cho cuộc gọi ajax, tôi nhìn thấy cả hai thông báo tại đồng thời
video saved successfully
There were some errors while saving the video. Please try in a while
Đó có phải là tôi không thực hiện cuộc gọi ajax đúng không?
CẬP NHẬT
thay đổi done
-success
kết quả trong cùng một hành vi
// 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 }}',
},
success: bootstrap_alert.success('video saved successfully'),
fail: bootstrap_alert.error('There were some errors while saving the video. Please try in a while')
});
Câu trả lời là máy chủ HTTP/1.0" 200 3200
, tôi tin rằng các fail
không nên được gọi
Bạn có chắc chắn '$ ('# feature')' không bị sửa đổi bởi một phần khác của mã không? –
Có, nó không được sửa đổi – fullstackcrash