How to get pure XMLHTTPRequest object in jQuery 1.5?

前端 未结 3 1465
挽巷
挽巷 2020-12-31 22:30

My code works fine in jquery 1.4 and i try upgrade it to 1.5. But this part of code stop working - its standard beforeSend handler

beforeSend: function (xhr,         


        
3条回答
  •  Happy的楠姐
    2020-12-31 23:03

    Extending Raphaels answer to include percentages...

            $.ajax({ 
                type: 'POST',
                success: function(data) 
                {   
    
                }
                xhr: function() {
                    var xhr = jQuery.ajaxSettings.xhr();
                    if(xhr instanceof window.XMLHttpRequest) {
                        xhr.upload.addEventListener('progress', function(){
                            var percent = 0;
                            var position = event.loaded || event.position; /*event.position is deprecated*/
                            var total = event.total;
                            if (event.lengthComputable) {
                                percent = Math.ceil(position / total * 100);
                            }
    
                            var percentVal = percent+ '%';
                            $('#progressBar').css('width',percentVal);
                            $('#uploadPercentage').html(' '+percentVal);
                        }, false);
                    }
                    return xhr;
                },                                  
            }); 
    

提交回复
热议问题