简体   繁体   中英

Perl CGI onclick call perl subroutine

I want to call a perl subroutine in Perl CGI. I know I need the onClick event but not sure how to use it correctly to call "TestSbub". Can anyone help?

<input type="button" value="submit" onClick="process('')">


sub TestSub {
    ###Do some code###
}

You can't, at least not directly.

onclick is a client-side JavaScript function. CGI code runs on the server.

To call a Perl sub you need to:

  1. make an HTTP request to a URL
  2. have your server trigger a CGI program for that URL
  3. have that program call the sub (eg by examining values in the query string to decide to call it).

The simple way to make that HTTP request would be to use a link or to submit a form. If you want to use JavaScript then you can assign a value to location or use the XMLHttpRequest object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM