简体   繁体   中英

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. jQuery sample:

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 Example in Python:

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

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

Then include this in your HTML page:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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