主题 : javascript获取CGI返回值 复制链接 | 浏览器收藏 | 打印
大笑笑大
级别: 骑士
UID: 25314
精华: 8
发帖: 184
金钱: 1320 两
威望: 264 点
综合积分: 528 分
注册时间: 2010-07-22
最后登录: 2014-10-11
楼主  发表于: 2011-07-11 17:26

 javascript获取CGI返回值

在6410下使用boa做web服务器,
想在pc上得到boa服务器上某个进程的pid值,
http://127.0.0.1/getpid.cgi网页显示6844,即纯文本格式。
现想在网页上将该pid的值传递给一个变量,来判断该pid值是否为0,不知道该如何做?
我查考了mjpeg-stream里面的javascript.html里面的一段代码。
<script type="text/javascript">

      /* Copyright (C) 2007 Richard Atterer, richard©atterer.net
       * This program is free software; you can redistribute it and/or modify it
       * under the terms of the GNU General Public License, version 2. See the file
       * COPYING for details.
       */

      var imageNr = 0; // Serial number of current image
      var finished = new Array(); // References to img objects which have finished downloading
      var paused = false;
      var previous_time = new Date();
      var pid_value= "123456";

      function createImageLayer() {
        //pid_value="/getpid.cgi";
        //document.getElementsByTagName('head')[0].appendChild(document.createElement('txt')).src='/getpid.cgi';
        //pid_value = head;
        var img = new Image();
        img.style.position = "absolute";
        img.style.zIndex = -1;
        img.onload = imageOnload;
        img.onclick = imageOnclick;
        img.width = 512;
        img.height = 384;
        img.src = "/webcam.cgi?action=snapshot&n=" + (++imageNr);
        var webcam = document.getElementById("webcam");
        webcam.insertBefore(img, webcam.firstChild);
      }

      // Two layers are always present (except at the very beginning), to avoid flicker
      function imageOnload() {
        this.style.zIndex = imageNr; // Image finished, bring to front!
        while (1 < finished.length) {
          var del = finished.shift(); // Delete old image(s) from document
          del.parentNode.removeChild(del);
        }
        finished.push(this);
        current_time = new Date();
        delta = current_time.getTime() - previous_time.getTime();
        fps   = (1000.0 / delta).toFixed(3);
        document.getElementById('info').firstChild.nodeValue = delta + " ms (" + fps + " fps)" + pid_value;
        previous_time = current_time;
        if (!paused) createImageLayer();
      }

      function imageOnclick() { // Clicking on the image will pause the stream
        paused = !paused;
        if (!paused) createImageLayer();
      }

    </script>
其中img.src = "/webcam.cgi?action=snapshot&n=" + (++imageNr);
是可以直接传图像数据的。
而我定义一个变量var pid_value="/getpid.cgi"是不行的。
麻烦高手帮忙解答下,谢谢。
大笑笑大
级别: 骑士
UID: 25314
精华: 8
发帖: 184
金钱: 1320 两
威望: 264 点
综合积分: 528 分
注册时间: 2010-07-22
最后登录: 2014-10-11
1楼  发表于: 2011-07-11 17:30
我getpid.cgi的源码如下
int main(int argc,char *argv[])
{
    //printf("%s\r\n\r\n","Content-Type:text/html");
    printf("%s\r\n\r\n","Content-Type:text/plain");
    printf("%s\r\n","1234856");
    return 0;
}