my upload js
$(document).ready(function() {
$('form').on('submit', function(event) {
event.preventDefault();
//append file to formdata
var formData = new FormData($('form')[0]);
//var input_video = $('#id_video');
//var file = input_video[0].files[0];
//formData.append("file", file);
$.ajax({
xhr : function() {
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', function(e) {
console.log('Bytes Loaded: ' + e.loaded);
console.log('Total Size: ' + e.total);
console.log('Percentage Uploaded: ' + (e.loaded / e.total));
var percent = Math.round((e.loaded / e.total) * 100);
$('#progressBar').attr('aria-valuenow', percent).css('width', percent + '%').text(percent + '%');
});
return xhr;
},
type : 'POST',
url : '/add-account/',
data : formData,
processData : false,
contentType : false,
success : function(data) {
var url = window.location.href.replace('/add-account/', '/account-detail/') + data.account_id;
window.location.assign(url);
}
});
});
});
وقمت بتعديل ال view لتقوم بارجاع id العنصر الجديد لاعادة توجيهه لصفحة تفاصيل العنصر بعد الرفع ولكن من نفس js
data = {
'account_id': account.pk,
}
#return redirect('account_detail', account_id=account.id)
return JsonResponse(data)
كما تلاحظ كان الارجاع عبارة عن اعادة توجيه لصفحة account_detail
الان التوجيه اصبح من js بهذا الشكل:
success : function(data) {
var url = window.location.href.replace('/add-account/', '/account-detail/') + data.account_id;
window.location.assign(url);
}
لكن المشكلة الرئيسية لم تحل بعد
في ال console
اول قيمة تتم طباعتها هي تم التحميل ١٠٠٪
لاحظ الحجم الخاص بالفورم تقريبا كحجم الفيديو واكثر بكم بايت
الامر الاخر ان ميثود التحقق يتم تنفيذها بعد مرور ١٠-١٥ ثانية يعني التحميل ينجح عن طريق ajax ويتم تحويلي لصفحة التفاصيل
لكن من اول مرة يتم طباعة قيمته كاملة وتتم طباعته مرة واحدة اليس المفروض progress يعمل بشكل مستمر