Ho un ajax
chiamata comejQuery: Funziona Ajax entrambi i gestori - fatto e non riescono
$.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')
});
e le azioni come
// 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>');
}
Quando la parte anteriore fa la chiamata ajax, vedo entrambe le notifiche a allo stesso tempo
video saved successfully
There were some errors while saving the video. Please try in a while
È che non sto effettuando correttamente la chiamata ajax?
UPDATE
cambiando done
a success
risultati in stesso comportamento
// 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')
});
La risposta del server è HTTP/1.0" 200 3200
, credo che la fail
non dovrebbe ottenere chiamato
Sei sicuro che '$ ('# funzione')' non è modificato da un'altra parte del tuo codice? –
Sì, non viene modificato – fullstackcrash