通过 javascript 执行 CGI 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8962757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:09:28  来源:igfitidea点击:

Executing a CGI script via javascript

javascriptcgi

提问by Jakob Weisblat

How can I make a cgi script be executed when a javascript function is called? Currently I am using a small iframe and loading the cgi script there, but it does not seem to be working. here is a snippet of code:

如何在调用 javascript 函数时执行 cgi 脚本?目前我正在使用一个小的 iframe 并在那里加载 cgi 脚本,但它似乎不起作用。这是一段代码:

function back()
{
    document.getElementById("hidden").src="scripts/backImage.cgi";//execute background script
    document.getElementById("scan").src="scripts/getImage.cgi";//reload the display iframe
}

回答by Michael Krelin - hacker

You can use XMLHttpRequestto trigger access to your cgi script.

您可以使用XMLHttpRequest触发对 cgi 脚本的访问。

回答by Douglas

You can use jQuery.ajax, or the shorthand:

您可以使用jQuery.ajax或简写:

jQuery.get("scripts/backImage.cgi");

回答by malonso

If you can use a JS library like jquery take a look at https://stackoverflow.com/a/861808/211097.

如果您可以使用像 jquery 这样的 JS 库,查看https://stackoverflow.com/a/861808/211097

Code snippet from that answer:

该答案的代码片段:

$.ajax({
    type:'get',
    url:'http://mysite.com/mywebservice',
    success:function(data) {
        alert(data);
    }
});