简体   繁体   English

在ajax上传中未调用成功

[英]Success not being called on ajax upload

My script is an upload page which has a progress bar. 我的脚本是一个带有进度条的上传页面。 The file is uploading correctly to the server and the progress bar is working. 该文件已正确上载到服务器,并且进度条正在工作。 The on success isn't being executed though and I have no idea why. 成功的执行虽然没有执行,但我也不知道为什么。 The console has no errors and the xhr response is "file moved do logic" so why isn't the success being called? 控制台没有错误,并且xhr响应是“文件移动了逻辑”,那么为什么不调用成功呢?

    <script type="text/javascript">
    $(document).ready(function() { 
    $('#progressbar').progress();

     $('#uploadForm').submit(function(e) {  

        //return Validate();    
        var ext = $('#userImage').val().split('.').pop().toLowerCase();
        if($.inArray(ext, ['gif','png','jpg','jpeg','pdf']) == -1) {
            alert('We only acccept PNG, JPG, JPEG, GIF or PDF files');
            return false; 
        }
        if($('#userImage').val()) {
            e.preventDefault();
            //$('#loader-icon').show();
            $(this).ajaxSubmit({ 
                target:   '#targetLayer', 
                beforeSubmit: function()
                 {
                  $("#progress-bar").width('0%');
                },
                uploadProgress: function (event, position, total, percentComplete){ 
                    $('#progressbar').progress({
                      percent: percentComplete
                    });
                    $('#progresslabel').html(percentComplete + '% Uploaded')
                },

                success:function (data){
                    alert (data);
                },
                resetForm: true 
            }); 
            return false; 
        }
    });
}); 
</script>
<div class="ui page grid">
    <div class="fifteen wide column">
        <div class="ui segment">
            <div class="upload">
                <h3>Upload <?php echo $pdf['UPLOADTITLE']; ?></h3>
                <form name="uploadform" id="uploadForm" action="upload.php" method="post">
                    <div>
                        <label>Upload Image File:</label>
                        <input name="userImage" id="userImage" type="file" class="demoInputBox" />
                    </div>
                    <div>
                        <input type="submit" id="btnSubmit" value="Submit" class="btnSubmit" />
                    </div>
                    <input type="hidden" value="<?php echo $pdf['UPLOADSTUDENT']?>" name="studentid">
                    <input type="hidden" value="<?php echo $pdf['UPLOADTITLE'] ?>" name="filetype">
                    <input type="hidden" value="<?php echo $pdf['UPLOADID']; ?>" name="uploadid">
                </form>
            </div>
            <div class="ui teal progress" id="progressbar">
                <div class="bar"></div>
                <div class="label" id="progresslabel">0% Uploaded</div>
            </div>

        </div>
    </div>
</div>

The problem was with : 问题出在:

 target:   '#targetLayer', 

As soon as I removed this the onSuccess was called. 删除此链接后,就会立即调用onSuccess。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM