我有这个来上传文件并获得进度条。我想将上传的文件限制为仅 pdf,不幸的是它不适用于 JQuery 验证插件:
$(document).ready(function(){
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('#up-form').validate({
rules: {
uploadedfile: {
required: true,
accept: "application/pdf",
},
},
messages: {
uploadedfile: "File must be PDF",
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
element
.addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
}
});
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
bar.width("100%");
percent.html("100%");
status.html(xhr.responseText);
}
});
})();
我该如何解决?对于我尝试上传的每个文件,我总是收到错误消息“文件必须是 PDF”。
我还在服务器端验证了扩展,但为了节省带宽,我想让它也是客户端
感谢您的帮助