【发布时间】:2016-07-21 16:39:21
【问题描述】:
我正在使用 PHP 脚本 (currentimage.php) 从我的闭路电视网络摄像机获取快照,效果很好:
<?php
while (@ob_end_clean());
header('Content-type: image/jpeg');
// create curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.20/Streaming/channels/1/picture');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
?>
和另一个 PHP/HTML 来显示数据:
<IMG id="myImage" SRC='currentimage.php'>
但我无法让它每 30 秒刷新一次背景图像。 我正在尝试 AJAX,但没有成功:
<script>
function refresh_image(){
document.getElementbyId("myImage").setAttribute("src", "currentimage.php");
}
setInterval(function(){refresh_image()}, 30000);
</script>
我做错了什么?我将不胜感激任何帮助
【问题讨论】: