Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

javascript - How to show file upload status in Laravel?

I have a controller that takes a lot of data by file and inserts it into the database. How can I show the user some status about how much code is run.

For example, I want to show statuses like, "file upload was done", "data is being validated", "data is inserted" etc. My initial approach was to use the session.

I inserted something like the following in appropriate places on controllers.

..
..code for file upload
..
session()->put('_order_upload_status','file upload done');

..
..code for validation
..
session()->put('_order_upload_status','data is being validated');

Then on the front end, I ran a bit of js code to get the status periodically.

function intervalAction()
  {
    var intervalID = window.setInterval(getStatus, 500);
  }
function getStatus()
  {
    var request = new XMLHttpRequest();
    var url = '{{ route('order.upload.getStatus') }}';
    request.open('GET',url,true);

    request.onload = function(){
      document.getElementById('percentageModalTextBox').innerHTML = this.response
    };
    request.send();
  }

The url {{ route('order.upload.getStatus') }} does nothing more than to get the session data.

However, this approach is not working. I can get the correct session only after the file upload controller runs completely. So I am getting nothing for a long time and only the last status after everything is over.

How can I show the status update to the user?

question from:https://stackoverflow.com/questions/65913608/how-to-show-file-upload-status-in-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...