Avatar of Tintin
Tintin
 asked on

Simple Perl/AJAX Form

I'm after the barebones to pass a single value to a Perl CGI via query and output the result.

The HTML I need to modify is:

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>

<div class="input-form">
     <input type="text" name="field1" class="form-control" placeholder="Enter to search...">
                    <span class="input-btn">
                        <button class="btn" id="check" type="button"><i class="b-search"></i></button>
                    </span>
</div>

<div class="result">
The output of the Perl CGI Script
</div>

Open in new window


What HTML/JS modifications do I need to make to invoke my Perl CGI script?
JavaScriptHTMLjQuery

Avatar of undefined
Last Comment
Md Shah

8/22/2022 - Mon
SOLUTION
Md Shah

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Tintin

ASKER
Hi Md.

I tried your javascript, and could get the Perl script to fire, but couldn't get any results displayed.

Should the script using the MIME type text/html, or something else?

Dave, I got your solution to work, but I'm unsure how to trigger the action on a button press, rather than a traditional HTML form.

Also, I'm trying to get the spinning graphic displayed while the script is running.
Tintin

ASKER
Finally managed to cobble together a combination of the two approaches.

My javascript looks now looks like:

$(function () {

        $('.btn').on('click', function (e) {


	    e.preventDefault();
            var site = $("[name='field1']").val();
	    url = 'search.pl';
            var posting = $.post( url, { f1: site } );
	    posting.done(function( data ) {
               $( "#result" ).empty().append( data );

            });
        });
});

Open in new window

Md Shah

Thats a Good News.. So I guess, You issue has been resolved..

Good Luck for further coding :)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy