This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

http服务中的cgi和javascript的数据交互



请问如何在cgi函数中将一个数组或一段内存数据传递给javascript

  • 用这种方法,只是将数据在控制台打印了出来
    void senddata(void)
    {
    int i=0;
    printf("Content type: text/html\n\n");
    for(i=0;i<100;i++)
    {
    printf("%d",i);
    printf("|");
    }
    }
    --------------------------------------------------------------------------------------
    // JavaScript Document
    function createXHR() 
    {
        var xhr;
     
     
        try 
        {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        
        catch (e) 
        {
            try 
            {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(E) 
            {
                xhr = false;
            }
        }
     
        if (!xhr && typeof XMLHttpRequest != 'undefined'
        {
            xhr = new XMLHttpRequest();
        }
     
        return xhr;
    }
     
    function sender() 
    {
        xhr = createXHR();
     
        if(xhr)
        {
            xhr.onreadystatechange=callbackFunction;
            //xhr.open("GET", "test.cgi?cur_time=" + new Date().getTime());
        xhr.open("GET","20120721.cgi?fuck");
        setTimeout("sender()",1000);
            xhr.send(null);
        }
        else
        {
            alert("send create failure");
        }
    }
    function callbackFunction()
    {
        if (xhr.readyState == 4) 
        {
            if (xhr.status == 200) 
            {
                var returnValue = xhr.responseText;
     
                if(returnValue != null && returnValue.length > 0)
                {
                    var arr=returnValue.split('|');
            }
                else
                {
                    alert("open failure");
                }
            
            else 
            {
                alert("others");
            }
        }
    }
  • 调用函数script_env.traceWrite,比如:

    script_env.traceWrite("TEST COMPLETE. " +exceptionCount+ " exception happened!")