html
<form id="video_form" enctype="multipart/form-data" >
<input class="files" type="file" name="upfile" id="upfile" onchange="uploadvideo('upfile',this)" accept=".avi,.mp4,.wmv,.rmvb,.flv,.rm">
</form>
JS
<script type="text/javascript">
var xhrOnProgress = function (fun) {
xhrOnProgress.onprogress = fun;
return function () {
var xhr = $.ajaxSettings.xhr();
if (typeof xhrOnProgress.onprogress !== 'function')
return xhr;
if (xhrOnProgress.onprogress && xhr.upload) {
xhr.upload.onprogress = xhrOnProgress.onprogress;
}
return xhr;
}
}
function uploadvideo(name, elem) {
var file = elem.files;
if (file.length == 0) return false;
if (file[0].size > 30 * 1024 * 1024) {
return false;
}
$("#video_form").ajaxSubmit({
url: 'url',
dataType: "text",
cache: false,
processData: false,
contentType: false,
timeout: 120000,
type: 'POST',
data: $("#video_form").serialize(),
beforeSend: function (data) {
},
xhr: xhrOnProgress(function (e) {
var percent = e.loaded / e.total;
percent = parseInt(percent * 100);
console(percent)
}),
success: function (obj) {
var result = $.parseJSON(obj);
},
complete: function (XMLHttpRequest, status) {
if (status == 'timeout') {
}
}
});
}
</script>