あなたがこれに答えたことがあるかどうかはわかりませんが、私は同じ問題を抱えていました、これが私の解決策ですAJAX jquery
$(function(){
$("#itemList").on("click", "a.downloadLink", function(){ //this binds a click event handler on the itemList container that will listen out for any a with class of downloadLink inside it being clicked
var link = $(this);
var item = link.parent();
var forId = item.data("itemid");
var started = new Date(); //the alternative to tracking time elapsed is to just use a simple counter you increment - "poll 5 times" etc. if your doing .5 second intervals, then 5 times = 2.5 seconds for example. Time elapsed may result in less polls, if a poll takes a long time to return, for example. Use whichever approach feels better.
var maxTime = 5000; //5 seconds
function poll(){
$.ajax({
type: "POST",
url: "Watergetstatus.php",
data: {FID: forId}, //this will be turned into a request for page1?forId=1&oldValue=2 - I expect it in this example to return a json-encoded response of {"changed":true|false, "newHtml":"replacementContent on success"}
datatype :'json',
success: function(data){
if (data.changed=true)
{
window.location.reload(true);
}
else {
var elapsed = (new Date())-started;
//window.location.reload(true);
if (elapsed <= maxTime) setTimeout(poll, 500); // Poll again in .5 seconds
//else you can assume the link didn't open / work / the database never changed etc - handle or ignore as needed
}
},
error: function() {
alert("borken"); //the request to the server bombed out; up to you if you want to simply re-queue for another try like above until the expiry time or if you want to show an error or just simply ignore it.
}
});
}
setTimeout(poll, 500); //wait 0.5 seconds before polling
});
});
HTMLには動的リンクの大規模なリストがありました
<div data-itemid="<?php echo $row_Files['FID']; ?> " >
<a class="downloadLink" href="PLC_FILES/WaterCheckOut.php?FID=<?php echo $row_Files['FID']; ?> " target=""><img src="PLCImages/download.fw.png"></a>
</div>
ポーリングファイルwatergetstatus.php
mysql_select_db($database_PLC, $PLC);
$query_files = "SELECT * FROM files WHERE FID = '{$_POST['FID']}'";
$files = mysql_query($query_files, $PLC) or die(mysql_error());
$row_files = mysql_fetch_assoc($files);
$totalRows_files = mysql_num_rows($files);
if($row_files['Status'] ==2)
{
$data= array("changed"=>true);
echo json_encode($data);
}
else
{
$data= array("changed"=>false);
echo json_encode($data);
}
ダウンロードファイルリンクwatercheckout.php
if ( $row_files['Status']==1 ) {
$file_path = $row_files['FileName'];;
$path_parts = pathinfo($file_path);
$file_name = $path_parts['basename'];
$file_ext = $path_parts['extension'];
$content_types = array(
"exe" => "application/octet-stream",
"zip" => "application/zip",
"mp3" => "audio/mpeg",
"mpg" => "video/mpeg",
"avi" => "video/x-msvideo",
);
$ctype = isset($content_types[$file_ext]) ? $content_types[$file_ext] : $ctype_default;
$file = $row_files['FileName'];
$path = "Historical/".date('Y-m-d-His');
$newfile = $path."_".$file;
$today = date('Y-m-d H:i:s');
header('Content-disposition: attachment; filename='.$file);
header("Content-Type: " . $ctype);
header('Content-Length: ' . filesize($file));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
mysql_select_db($database_PLC, $PLC);
mysql_query("UPDATE files SET Status = '2'");
ob_clean();
flush();
readfile($file);
rename($file, $newfile);
コードを簡略化してたくさん切り取ったので、何かが足りないかもしれませんが、これは私が使用した一般的なフレームワークであり、私にとってはうまくいきます
そこにはあまりなかったので、これが誰かを助けることを願っています