4

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
}
5
  • Can you use jquery or mootools? Commented Jan 22, 2012 at 16:56
  • I don't know anything about either of those. can you suggest somewhere to learn? Commented Jan 22, 2012 at 16:57
  • You won't need JQuery or mootools (or any other library for that matter) to achieve this. Commented Jan 22, 2012 at 17:02
  • @JeffreySweeney even when doing it from scratch, it would be good to abstract out the browser differences behind an API. And before writing the API, it would be good to know about the existing ones to demonstrate why the new API is better. I'm guessing that you are thinking along the lines of reducing the total size of the page, which in some cases is worthwhile. But again, someone else has probably written a decent minimal Ajax API too, so it would be worth looking into that before re-implementing it. Commented Jan 22, 2012 at 17:13
  • @Douglas Fair enough :) I was leaning on reducing total file size when I made my comment, but xmlhttprequest is pretty universal across different browsers anyway, the only real exception being that IE sees it as an ActiveX object. Because it is such a straight-forward procedure, making a user download an entire library (or even part of one) seems unnecessary for this instance. Commented Jan 22, 2012 at 17:31

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

4

You can use jQuery.ajax, or the shorthand:

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

Comments

0

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);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.