2013-02-28 133 views
0

开始运行我已经当我录制按钮单击下面的脚本开始运行加载图像。 我想显示图像时,我在录制按钮点击这是一样的一个通常显示的,当我们在上传图片... 这是脚本:显示当阿贾克斯在后台

<script> 
function st() 
{ 
    if (window.XMLHttpRequest) 
    { 
     xmlhttp=new XMLHttpRequest(); 
    } 
    else 
    { 
     xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
    } 
    xmlhttp.onreadystatechange=function() 
    { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
     alert('RECORDING Start'); 
     } 

    } 
    xmlhttp.open('GET','http://localhost/IPCAM/start.php;) 

    xmlhttp.send(); 

setTimeout('st()',5000); 
} 
</script> 

这当我按一下按钮这个按钮的ajax开始背景。

<button OnClick="st()">Record</button> 

我没有想法做到这一点,请有人可以帮助我。

+0

是什么'st'吗? – 2013-02-28 21:15:03

+0

st()是对脚本的函数调用,它开始执行一个从ip摄像头获取帧的页面record.php。 – 2013-02-28 21:17:24

+0

你正在引入一个不需要的全局'xmlhttp',并且你没有关闭字符串'http:// localhost/IPCAM/start.php'。而'setTimeout'的首选语法是'setTimeout(function,timer)'而不是'(string,timer)'。 – 2013-02-28 21:18:35

回答

1

首先我觉得你的问题很清楚,但让我试试:

请确保您有一个CSS类定义图片:

.recordingBackground 
{ 
    background-image: url("record.png"); 
} 

(或者只是使用JavaScript)

创建按钮:

<input type="button" id="recordButton" value="Record" /> 

让jQuery的听按钮,你可以添加类的元素:

$('#recordButton').live("click", function() 
{ 
    $('#background').addClass('recordingBackground'); 
    // Or use a similar method (for example: pure javascript). 
    // #background is just an example div. 
}); 
+0

你是不是指'addClass()'? – Archer 2013-02-28 21:28:37

+0

@阿奇尔哦,是的,对不起。固定。 – Jonast92 2013-02-28 21:32:58

+0

啊 - 不错的:) – Archer 2013-02-28 21:40:37

1

添加一个div id为loadingDiv和更改您的代码此

<script> 
function st() 
{ 
         if (window.XMLHttpRequest) 
         { 
          xmlhttp=new XMLHttpRequest(); 
         } 
         else 
         { 
          xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
         } 
         xmlhttp.onreadystatechange=function() 
         { 
          if (xmlhttp.readyState==1) 
          { 
          document.getElementById("loadingDiv").innerHTML = "<img src='loading.gif'/>"; 
          } 
          if (xmlhttp.readyState==4 && xmlhttp.status==200) 
          { 
          alert('RECORDING Start'); 
          } 

         } 
         xmlhttp.open('GET','http://localhost/IPCAM/start.php; 

         xmlhttp.send(); 

setTimeout('st()',5000); 
} 
</script> 
+0

此外,字符串“http:// localhost/IPCAM/start.php”未关闭。你的代码中也有一个全局变量'xmlhttp'。为什么不在'xmlhttp.send()'之后开始动画呢? – 2013-02-28 21:24:35

+0

感谢MIIB它的工作! – 2013-02-28 21:29:30