简体   繁体   English

如何通过javascript读取cgi文件

[英]how to read cgi file by javascript

如何在javascript中使用CGI程序的输出?

您读取任何其他服务器页面的方式相同:AJAX。

If your cgi file is placed inside web root directory, you can use Ajax to receive its content. 如果您的cgi文件位于Web根目录中,则可以使用Ajax接收其内容。 jQuery sample: jQuery示例:

var cgiContent ='';
$.get('cgi-bin/my.cgi', function(data) {
    cgiContent = data;
});

You can have your cgi output javascript commands in text and then include its output as you would include any other javascript file. 您可以让cgi以文本形式输出javascript命令,然后像包含其他任何javascript文件一样包含其输出。

CGI Example in Python: Python中的CGI示例:

print("Content-Type: text/plain")
print

print("var value = 'Hello World';")             

Then include this in your HTML page: 然后将其包含在您的HTML页面中:

<script type="text/javascript" src="/path/to/cgi/script.py"></script>
<script type="text/javascript"> document.write(value)</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM