Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:24:47+00:00 2026-05-22T21:24:47+00:00

Working with HTML5’s File API, the upload is made via an object called upload

  • 0

Working with HTML5’s File API, the upload is made via an object called upload in the XMLHttpRequest. This is the tutorial I’m working with (and the Google cache mirror since it’s down at the moment). This is the relevant part:

// Uploading - for Firefox, Google Chrome and Safari
xhr = new XMLHttpRequest();

// Update progress bar
xhr.upload.addEventListener("progress", function (evt) {

As you can see, to track the upload progress, the XMLHttpRequest object has a property named upload, which we can add an event handler.

My question is: has jQuery an equivalent?. I’m attempting to leave the code as clean as and cross-browser compatible as possible, for whenever Microsoft thinks it’s a good idea (although it sounds like it will be in 2012 or 2013).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:24:48+00:00Added an answer on May 22, 2026 at 9:24 pm

    Here is what I came up with to get around the issue. The $.ajax() call allows to provide a callback to generate the XHR. I just generate one before calling the request, set it up and then create a closure to return it when $.ajax() will need it. It would have been much easier if they just gave access to it through jqxhr, but they don’t.

    var reader = new FileReader();
    
    reader.onloadend = function (e) {
        var xhr, provider;
    
        xhr = jQuery.ajaxSettings.xhr();
        if (xhr.upload) {
            xhr.upload.addEventListener('progress', function (e) {
                // ...
            }, false);
        }   
        provider = function () {
            return xhr;
        };  
    
        // Leave only the actual base64 component of the 'URL'
        // Sending as binary ends up mangling the data somehow
        // base64_decode() on the PHP side will return the valid file.
        var data = e.target.result;
        data = data.substr(data.indexOf('base64') + 7); 
    
        $.ajax({
            type: 'POST',
            url: 'http://example.com/upload.php',
            xhr: provider,
            dataType: 'json',
            success: function (data) {
                // ...
            },  
            error: function () {
                // ...
            },  
            data: {
                name: file.name,
                size: file.size,
                type: file.type,
                data: data,
            }   
        }); 
    };  
    reader.readAsDataURL(file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with the HTML5's File API ( tutorial here ) and I need
I am currently working on the HTML5 File API, and I need to get
I'm uploading multiple files via XmlHTTPRequest and HTML5. I have the uploading working fine,
I've just started working with HTML5's File API. I've been able to mimick imgur's
I am working on this html5 file uploader plugin but it has a bug
I have a working version of HTML5 drag & drop file uploader. I was
I'm working on some HTML5 demo code, including stuff like <input type=date /> This
I'm working through an HTML5 drag and drop example http://www.sitepoint.com/html5-file-drag-and-drop/ , but can't figure
I 'm working on an html5 game which works on javascript library called propulsionjs.In
I'm working on a HTML5 canvas game using a JavaScript library called Propulsionjs.com. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.