如何通过javascript读取cgi文件

发布于 2024-10-04 22:46:21 字数 36 浏览 0 评论 0原文

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

How do I use the output of a CGI program in javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

命硬 2024-10-11 22:46:21

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

Same way you read any other server page: AJAX.

入画浅相思 2024-10-11 22:46:21

如果您的cgi文件位于Web根目录中,您可以使用Ajax来接收其内容。 jQuery 示例:

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

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;
});
月下客 2024-10-11 22:46:21

您可以让您的 cgi 以文本形式输出 javascript 命令,然后像包含任何其他 javascript 文件一样包含其输出。

Python 中的 CGI 示例:

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

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

然后将其包含在您的 HTML 页面中:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文