进度栏.Ajax设置

时间:2018-07-11 10:18:37

标签: jquery ajax xmlhttprequest progress-bar

我应该如何设置我的Ajax代码以查看上传进度栏?我从一个示例中获取该代码:

$.ajax({
       xhr: function () {
       var xhr = new window.XMLHttpRequest();
       xhr.upload.addEventListener("progress", function (evt) {
       if (evt.lengthComputable) {
          var percentComplete = evt.loaded / evt.total;
          percentComplete = parseInt(percentComplete * 100);
          console.log(percentComplete);
          if (percentComplete === 100) {
          }
       }
       }, false);
       return xhr;
    },
    url: posturlfile,
    type: "POST",
    data: JSON.stringify(fileuploaddata),
    contentType: "application/json",
    dataType: "json",
    success: function (result) {
    console.log(result);
    }
});

在HTML中,我有该输入文件:

<input type="file" name="Curriculum" id="Curriculum" style="display: none;" class="form__input" />
            <label for="Curriculum" id="LabelCurriculum" class="form__input" style="background-color: white; display: block; width: 100%; padding: 20px; font-family: Roboto; -webkit-appearance: none; border: 0; outline: 0; transition: 0.3s;">Clicca per allegare il Curriculum</label>

而ajax脚本位于js脚本中,该脚本具有我要上传的元素:

var element = document.getElementById("Curriculum");

任何人都可以帮忙吗?

0 个答案:

没有答案