How do I make an AJAX request to Perl script using jQuery blur event?

后端 未结 2 1804
轻奢々
轻奢々 2021-01-16 07:11

I want to call an Perl script in the blur function of my input field. But i dont really know how to do this, and i cant find any working things with google. my code of the h

相关标签:
2条回答
  • 2021-01-16 07:50

    You appear to have written a command line script, designed to be interacted with by a user running it in a shell. (The use of Getopt is a big clue here).

    In order to have it respond to an HTTP request you need to rewrite it so that it will work with a webserver (instead of a shell).

    There are several ways to do this. A simple approach would be to use CGI. A modern approach would be to use Plack, possibly in conjunction with a framework.

    A basic introduction to using Perl/CGI with Apache is available in the Apache documentation. You should look at a module such as CGI in order to process incoming data and emit HTTP headers correctly.

    You can find out more about Plack from the project's homepage, which includes links to a number of frameworks that use it.

    0 讨论(0)
  • 2021-01-16 08:01

    That worked for me, call it in the blur event:

    function perlExecute(name){
        XMLHttp.open("GET", "/cgi-bin/balance.pl?cardnumber="+name, true);
        XMLHttp.onreadystatechange = function() {
            if (XMLHttp.readyState == 4) {
                $("#balance").val(XMLHttp.responseText);
            }
        }
        XMLHttp.send(null);
    };
    
    0 讨论(0)
提交回复
热议问题