I'm trying to make a button that disables itself when uploading an image, the opload is done using AJAX. But the success callback is not working, (I can tell because not even the console show its content in console.log
. What am I doing wrong?
I changed the url part, now Iḿ receiving this on the console : POST http://192.168.0.229:8000/feed/add 419 (unknown status)
$(document).on('click', '[data-type-image]', function () {
$('#image_upload').click();
var formData = new FormData($(document));
$.ajax({
url: window.location.href,
type: 'POST',
data: formData,
beforeSend: function () {
console.log('before send working');
$('form').find('div').find('button').attr('disabled', true);
$('form').find('div').find('button').css('background-color', 'grey');
},
success: function(){
console.log('success working');
$('form').find('div').find('button').attr('disabled', false);
$('form').find('div').find('button').removeAttr('style');
},
error: function () {
console.log(error);
},
cache: false,
contentType: false,
processData: false,
xhr: function () { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) { // Avalia se tem suporte a propriedade upload
myXhr.upload.addEventListener('progress', function (e) {
}, false);
}
return myXhr;
}
});
});