基本上我正在发出一个简单的ajax请求
function upload(){
setInterval(function callMeOften()
{
$.ajax({
method: 'get',
url : 'uploadinfo.php?unique_id=<?php echo $some_uniq_id; ?>',
dataType : 'text',
success: function(text){ updatebar(text); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText);
}
});
}, 5000);
}
function updatebar(per){
$('#updateMe').animate({"width" : per});
}
到 php 脚本
$unique_id = $_GET['unique_id'];
$progress = uploadprogress_get_info($unique_id);
if(function_exists("uploadprogress_get_info")) {
if (floor(($progress['bytes_total']/1024)/1024) > 100){
echo "run";
} else {
if ($progress['bytes_uploaded'] == 0 || $progress['bytes_total'] == 0){
echo "100";
} else {
echo floor($progress['bytes_uploaded'] / $progress['bytes_total'] * 100);
}
}
}
该函数上传();使用 onsubmit() 调用;文件上传表单的操作
<form id="something" onsubmit="upload();" action="status.php" enctype="multipart/form-data" method="post">
我使用相对路径,请求在 FF 和 IE 中有效,但在 chrome、safari 和 opera 中,上传过程中甚至不会触发 ajax 请求。
这是怎么回事?
编辑:最后我只是在一个单独的窗口中显示了上传进度,该窗口是使用 onsubmit 操作创建的,并重新调整大小并重新定位到屏幕中心,看起来不错,是迄今为止最简单的方法