Content upload progress using ajax

281 Views Asked by At

I have a page in which user input content and save it.

I have a function which sends data to server using XMLHttpRequest. My requirement is to show a progress percentage while the data is being saved. Does any one know a way to do this?

I thought I could use SWFUpload, but it appears to be specific for file upload as opposed to dynamic content upload.

Any help will be much appreciated.

Thanks

1

There are 1 best solutions below

0
Samuel Zhang On

Latest XmlHttpRequest Level 2 spec has added support for Events. Specifically, you can show the upload progress something like:

xhr.upload.onprogress = function(evt) {
    if (evt.lengthComputable) {
        var percent = 100 * evt.loaded / evt.total;
        trace("[onprogress] " + percent);
    }
}

The only issue today is the lacking of support in all web browsers. Normally you'll have to work around this via Flash or back channel from server for progress notification. You can find many discussions in this site.