如果用户进入网站,则间隔(js)正在运行并且每秒调用PHP文件(用于更新文本和图像)。
但如果有人上传图片,他/她会被重定向到带有.php的网址。 我在底部输入了一个“标题”,以便在上传后将用户重定向回页面。
在桌面上,一切都很完美。在Android上,如果用户返回,PHP代码将无效。
gallery.php:
<?php
header( "Access-Control-Allow-Origin: *" );
$count = 0;
$oldcount = 0;
if ( $handle = opendir( "../../archive/images/" ) ){
while ( ( $file = readdir( $handle ) ) !== false ){
if ( !in_array( $file, array( ".", ".." ) ) && !is_dir( "../../archive/images/" . $file ) )
$count++;
}
}
if ( $count == $oldcount ){
exit;
}
else{
$oldcount = $count;
$count = 0;
$files = glob( "../../archive/images/" . "*.*" );
foreach( $files as $image ){
if ( $image ){
echo '<img src="' . $image . '" /></img>';
}
}
}
?>
在多个Androids上测试过它。每次都一样。似乎在上传内容后调用此代码有问题。
setInterval(
function(){
$( "#gallery" ).load( "system/communicate/gallery.php" );
$( "#chat" ).load( "system/communicate/output.php" );
}, 1000 );
任何想法为什么?这是一个已知的错误吗?
如果你想尝试,请做。这是我的网址:www.m7-studios.de user / email:test,pw:test
答案 0 :(得分:1)
Android浏览器可能会缓存您的1秒请求。
选项1 在您的gallery.php和output.php上 发送一些标题告诉它不要缓存
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
选项2 在字符串中添加一个随机数,以便android浏览器认为它是一个新文件
setInterval(
function(){
var myrandom=Math.random();
$( "#gallery" ).load( "system/communicate/gallery.php?random="+myrandom );
$( "#chat" ).load( "system/communicate/output.php?random="+myrandom );
}, 1000 );