我的脚本是一个上传页面,其中包含一个进度条。 文件正确上载到服务器,进度条正在运行。 虽然成功没有被执行,但我不知道为什么。 控制台没有错误,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>
答案 0 :(得分:0)
问题在于:
target: '#targetLayer',
一旦我删除了这个,就会调用onSuccess。