weixin_33717298 2013-10-29 16:51 采纳率: 0%
浏览 215

求助:xhr停止并产生错误?

在如下代码中,我使用同样的代码来上传图像和显示进度,尽管唯一的更改是上传音频文件,但xhr却停止并产生此错误:

[object Object]an error occurred

html:

<form enctype="multipart/form-data" id="audioForm">
    <p>Click browse to choose the audio file(mp3) from your PC (Maximum file size is 5mb)</p>
    <input type="file" name="audio" value="" class="input-xlarge required"><br />
    <label for="song_title">Song Title</label>
    <input type="hidden" name="act_id" value="<?=$act_id?>">
    <input type="text" class="form-control" id="song_title" name="song_title">
    <input type="button" class="btn btn-info" value="Upload Images" id="uploadAudio" />
</form>

<div id="progress" style="display:none;">
    <progress value="0" max="100"></progress>
</div>
<div id="response" style="display:none;"></div>

JQuery:

$('body').on('click', '#uploadAudio', function(){

        var form = new FormData($('#audioForm')[0]);
        $('#progress').fadeIn();

        // Make the ajax call
        $.ajax({
            url: '/ajax/actions/addAudio.php?act_id=<?=$act_id?>',
            type: 'POST',
            xhr: function() {
                var myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){
                    myXhr.upload.addEventListener('progress',progress, false);
                }
                return myXhr;
            },
            success: function (res) {
                $('#progress').hide();
                $('#response').show();
                $('#response').html(res);
                $("#audioDisplay").load('/ajax/display/audioDisplay.php?act_id=<?=$act_id?>');
            },
            error: function(res){
                $('#progress').hide();
                $('#response').show();
                $('#response').html(res + 'an error occurred');
            },
            data: form,
            cache: false,
            contentType: false,
            processData: false
         });
});

有什么问题吗?

新的错误功能:

error: function(jqXHR, textStatus, errorThrown){
    $('#response').html('textStatus: ' + textStatus + '<br>errorThrown: ' + errorThrown);
},

返回错误如下:

textStatus: error
errorThrown: TypeError: Argument 2 of EventTarget.addEventListener does not implement interface EventListener.
  • 写回答

1条回答 默认 最新

  • 北城已荒凉 2013-10-29 17:03
    关注

    You should use the complete form of the error function:

    error: function(jqXHR, textStatus, errorThrown) {
       ...
    }
    

    textStatus and errorThrown will provide you with more information about the nature of the error.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记