简体   繁体   English

Perl CGI onclick调用perl子例程

[英]Perl CGI onclick call perl subroutine

I want to call a perl subroutine in Perl CGI. 我想在Perl CGI中调用一个perl子例程。 I know I need the onClick event but not sure how to use it correctly to call "TestSbub". 我知道我需要onClick事件,但不确定如何正确使用它来调用“ 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. onclick是客户端JavaScript函数。 CGI code runs on the server. CGI代码在服务器上运行。

To call a Perl sub you need to: 要调用Perl子程序,您需要:

  1. make an HTTP request to a URL 向URL发出HTTP请求
  2. have your server trigger a CGI program for that URL 让您的服务器为该URL触发CGI程序
  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. 发出HTTP请求的简单方法是使用链接或提交表单。 If you want to use JavaScript then you can assign a value to location or use the XMLHttpRequest object. 如果要使用JavaScript,则可以将值分配给location或使用XMLHttpRequest对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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