aaazalea
aaazalea

Reputation: 7930

Executing a CGI script via javascript

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:

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

Upvotes: 4

Views: 16813

Answers (3)

malonso
malonso

Reputation: 2295

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

Code snippet from that answer:

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

Upvotes: 0

Douglas
Douglas

Reputation: 37781

You can use jQuery.ajax, or the shorthand:

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

Upvotes: 4

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143329

You can use XMLHttpRequest to trigger access to your cgi script.

Upvotes: 5

Related Questions