我正在尝试让 lighttpd 1.5 的上传进度模块工作,但我遇到了一个奇怪的问题:
当我开始上传时,“/response”每秒都会被调用,并设置了 X-Progress-ID 标头,但我没有得到任何响应。GET 调用只是加载和加载,但没有得到响应。如果手动调用它(localhost/response?X-Progress-ID=someID),它似乎是正确的,received 和 total 的值是正确的并已设置。然后当我取消上传进度(通过浏览器中的“X”按钮)时,/response 不断被调用,但现在它将返回状态 200,但是,当然,没有设置正确的值。
这是我的代码:
Javascript:
interval = null;
function openProgressBar(uuid) {
/* call the progress-updater every 1000ms */
interval = window.setInterval(
function () {
fetch(uuid);
},
1000
);
}
function fetch(uuid) {
req = new XMLHttpRequest();
req.open("GET", "/progress", 1);
req.setRequestHeader("X-Progress-ID", uuid);
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
/* poor-man JSON parser */
var upload = eval(req.responseText);
document.getElementById('tp').innerHTML = upload.state;
/* change the width if the inner progress-bar */
if (upload.state == 'done' || upload.state == 'uploading') {
bar = document.getElementById('progressbar');
w = 400 * upload.received / upload.size;
bar.style.width = w + 'px';
}
/* we are done, stop the interval */
if (upload.state == 'done') {
window.clearTimeout(interval);
}
}
}
}
req.send(null);
}
还有我的 HTML:
<form id="upload" enctype="multipart/form-data"
action="index.php?X-Progress-ID={{tracking_id}}"
method="post"
onsubmit="openProgressBar('{{tracking_id}}'); return true;">
<input name="video" type="file" />
<input type="submit" class="button orange medium" value="Upload" />
</form>
<div>
<div id="progress">
<div id="progressbar"></div>
</div>
<div id="tp">(progress)</div>
</div>
编辑:忘了提... {{tracking_id}} 正在php控制器中生成并用Twig打印。