-1

How to call a perl script which is returning data "text" type inside a html file.Posting the perl script for reference.This script has to be called in the index.html so how to do that

#!/usr/bin/perl -w  

use CGI;  

my $cgi = CGI->new;  
my $remote = $cgi->remote_host();  

my $AB = "16.108";  
my $CD = "16.214";  
my $EF = "10.99";  
my $GH = "10.243";  
my $XY = "10.179";  

my @remote_ip_values = split(/\./, $remote);  

my $remote_ip = $remote_ip_values[0] .".". $remote_ip_values[1];  

print "Content-type: text/html\n\n";  
print "document.write(\"<style>\\n\");\n";  
print "document.write(\"font color:red;\\n\");\n";  


if ($remote_ip eq $AB)  
{  
print "document.write(\"SUCCESSFUL\");\n";  

}  
 else  
{  
print "document.write(\"TEST\");\n";  
}  
exit;  
BeastLesnar
  • 71
  • 1
  • 3
  • 7

1 Answers1

-1

I am editing my answer as I now understand what you are trying to do. I have set up a simple example which will load the content from "another website" - which for you will be your Perl CGI.

This HTML uses some simple JQuery. I am loading the following HTML page, http://chocksaway.com/tester.html and copying the contents into the "test" div:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Loader</title>
    </head>
    <body>
        <div id="test"></div>
            <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#test').load('http://chocksaway.com/tester.html');
                });
            </script>
    </body>
</html>

http://chocksaway.com/tester.html has the following HTML:

<html>
    <header></header>
    <body> 
        this is a test so there
    </body>
</html>

If you open you http://chocksaway.com/tester2.html, you will see:

this is a test so there

Replace "http://chocksaway.com/tester2.html" with the URL of your Perl CGI.

chocksaway
  • 870
  • 1
  • 10
  • 21
  • Yes the script is working in the browser.I am getting the desired text in the browser.Now what i want is to call this script inside the index.html so that index webpage gets the desired text along with other stuffs – BeastLesnar Jun 25 '17 at 10:44
  • You can make a call with ajax, and JQuery. This will allow you to make a call to your Perl CGI. This makes a call to a weather API. https://gist.github.com/npearson72/4102982 which 'does' what I am describing. – chocksaway Jun 26 '17 at 09:06
  • I have updated the answer, with a practical example, which shows you how to use some Javascript / JQuery to load the contents of your CGI into a "div". – chocksaway Jun 26 '17 at 16:27