Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. $(function(){
  2. var progressBar = $('progress');
  3. $('#my_form').on('submit', function(e){
  4. e.preventDefault();
  5. var $that = $(this),
  6. formData = new FormData($that.get(0));
  7. $.ajax({
  8. url: $that.attr('action'),
  9. type: $that.attr('method'),
  10. contentType: false,
  11. processData: false,
  12. data: formData,
  13. dataType: 'json',
  14. xhr: function(){
  15. var xhr = $.ajaxSettings.xhr();
  16. xhr.upload.addEventListener('progress', function(evt){
  17. if (evt.lengthComputable) {
  18. var percentComplete = Math.ceil(evt.loaded / evt.total * 100);
  19. $('#example5')
  20. .progress({
  21. value : percentComplete,
  22. total : 100,
  23. })
  24. ;
  25. progressBar.val(percentComplete).text(percentComplete + '%');
  26. document.getElementById("status").innerHTML = 'Uploading...';
  27. }
  28. }, false);
  29. return xhr;
  30. },
  31. success: function(json){
  32. if(json){
  33. $that.after(json);
  34. }
  35. document.getElementById("status").innerHTML = 'Successfully uploaded.';
  36. },
  37. error: function() {
  38. document.getElementById("status").innerHTML = 'There was an error.';
  39. }
  40. });
  41. });
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement