jQuery变量未定义,但控制台显示它包含一个值

时间:2019-01-29 16:35:30

标签: javascript jquery

下图显示了以下代码块中console.log(data)的结果,但是console.log(data.result)返回undefined。起初我以为这是一个数组,但是data[0].resultdata[0]都显示未定义。对我来说也很奇怪,如果我输入console.log(data.bitrate)或contentRange等,它们都将返回值。

Console.log

这是我在其中使用的代码,fileupload来自库here

$(function() {
  var maxChunkSize = .5 * 1024 * 1024; //SET CHUNK SIZE HERE (.5 mb)

  $('.PicturesForm').fileupload({
    maxChunkSize: maxChunkSize,
    url: 'forms/vehicle_Pictures.cfm', //URL WHERE FILE TO BE UPLOADED
    error: function(jqXHR, textStatus, errorThrown) {
      // Called for each failed chunk upload
    },
    success: function(data, textStatus, jqXHR) {
      /*This event will be called on success of upload*/
      var count = parseInt($(this.form).find('[name=counter]').val()) + 1;
      $(this.form).find('[name=counter]').val(count);
    },
    submit: function(e, data) {
      /*This event will be called on submit here i am adding variable to form*/
      $(this).find('[name=fileName]').val(data.originalFiles[0].name);
      $(this).find('[name=numberOfChunks]').val(Math.ceil(data.originalFiles[0].size / maxChunkSize));
      $(this).find('[name=counter]').val('1');
    },
    progress: function(e, data) {
      console.log(data.bitrate);
      console.log(data);
      console.log(data[0]);
      console.log(data[0]);
      console.log(data[0].result);
      $(this).find('[name=progressBar]').html(data);
    }
  });
});

0 个答案:

没有答案