2

I have HTML and Javascript that passes Form Input variables to a server Perl cgi that works when Form Submit button is clicked (Post, Action, etc). I write it, but not much experience in that environment.

Question is, I want the cgi to be spawned automatically (hopefully silently) when the HTML page is loaded. The Javascsript runs when loaded, but is there a way for it to then call the server cgi automatically (and pass the Form variables), without the form Submit button? I fear Form requires Submit, but any exceptions? Or alternately, I know how to pass a parm string to the cgi, but I don't know how to spawn it automatically from Javascript? Typing http://...cgi spawns it, but automatically?

The cgi does have the option to "show no print" on screen, silently, in which case, can it run asynchronously, without needing a "return" back to restore the browser control? Cgi could return via a spawn of the referrer page (a second load)? But is that necessary? As is, because of the printed screen from Submit, it does need a manual return.

Everything else is working, but both the automatic spawn and the silent return are a puzzle? Ideas appreciated.

WayneF
  • 235
  • 2
  • 10
  • You can do this using [Ajax](https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started). If you use jQuery, you can [use the `$.ajax()` function](http://www.sitepoint.com/use-jquerys-ajax-function/), which I find a lot less clunky than the pure JS approach. – ThisSuitIsBlackNot May 14 '15 at 20:44

1 Answers1

1

If I understand the question correctly, you want to send a request to a server on page load.

You can do it pretty simple and straightforwardly via Javascript since submitting a form is not the only way to send a request. What you want is called AJAX.

If you use jQuery, read about ready and ajax.

If you don't use jQuery, there is still a way to execute any Javascript on page load and to send a request (but you still better consider using jQuery).

Community
  • 1
  • 1
Vadim Pushtaev
  • 2,332
  • 18
  • 32
  • Thanks much to both of you. That is sounding right, and I think I have the idea now. I'll dive into it.. Looks like a new world though... learning curve. :) – WayneF May 14 '15 at 22:31