Ajax进度栏,直到我的成功功能完成

时间:2019-06-14 21:15:44

标签: jquery ajax

我正在实现ajax进度条,我希望在我的ajax成功功能完成之前进度不会达到100%。

isBST(root)

我的ajax进度条显示100%,但仍然等待成功功能完成。因此,我希望在执行成功功能之前,进度条不应该达到100%。

1 个答案:

答案 0 :(得分:0)

尝试如下操作,所以只有完成后它才是100%。

html

<progress></progress>

jQuery代码

$.ajax({
        url: url,
        type: 'POST',
        enctype: 'multipart/form-data',
        //Form data
        data: new FormData($('#fileupload-form')[0]), // Data sent to server, a set of key/value pairs representing form fields and values
        // Tell jQuery not to process data or worry about content-type
        // You *must* include these options!
        cache: false, // To unable request pages to be cached
        contentType: false, // The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded"
        processData: false, // To send DOMDocument or non processed data file it is set to false (i.e. data should not be in the form of string)
        //Custom XMLHttpRequest
        xhr: function(){
            var myXhr = $.ajaxSettings.xhr();
            if (myXhr.upload) {
                // For handling the progress of the upload
                myXhr.upload.addEventListener('progress', function(e) {
                    if (e.lengthComputable) {
                        $('progress').attr({
                            value: e.loaded,
                            max: e.total,
                        });
                    }
                } , false);
            }
            return myXhr;
        },
        success: function(res){

        }
    });