我有以下脚本,当使用upload input上传文件时,它会显示一个加载器。我希望加载器应该出现,直到文件上传的时间,也希望捕获的文件的名称。有谁能告诉我这是怎么做的吗?
<input type="file" id="photoimg" name="file" />
<div id='preview' align="center"></div>
<script type="text/javascript" >
$(document).ready(function() {
$('#photoimg').change(function(){
$("#preview").html('');
$("#preview").html('<img src=img/loader.gif" alt="Uploading...."/>');
$("#imageform").ajaxForm({
target: '#preview'
});
});
});
</script>
发布于 2018-02-06 18:35:09
您可以使用ajax call来执行此操作。单击upload按钮后,您可以显示加载器图像,如果成功,您可以将其隐藏,如果上传失败,则可以显示该图像的单独图像。
$.ajax({
url: 'YOUR API PATH',
"Show the loader once the ajax call made using .show() or similar"
error: function() {
"show the error image using .show() or similar"
},
success: function(data) {
"Hide the loader on success"
},
type: 'POST'
});
https://stackoverflow.com/questions/48640651
复制相似问题