Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3606054
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:12:02+00:00 2026-05-18T21:12:02+00:00

im having a setback, im making an Html page with javascript, and im using

  • 0

im having a setback, im making an Html page with javascript, and im using AJAX to call Perl functions. The thing is when my Perl program doesn’t need parameters the calling is trivial. But i have a function to open and read a file so i need to give the location of the file to the perl script, thus having to passe it trough a paramenter in the AJAX calling.
Ex working call:

function getOption(){
   var selectmenu=document.getElementById("Select1")
    selectmenu.onchange=function(){  //run some code when "onchange" event fires
    var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
    if (chosenoption.value!="nothing"){
     var s = chosenoption.text;
     openFile("C:\PerlTest\test.txt");
    } 
   }
  }

EX. not working trying to pass parameter:

function openFile(name){
 XMLHttp.open("GET", "/cgi-bin/readFile.pl"+name, true);
 XMLHttp.onreadystatechange = function() {
 if (XMLHttp.readyState == 4) {
    document.getElementById("TxtArea").innerHTML = XMLHttp.responseText;
     }
     }
     XMLHttp.send(null);
   }

Im attempting to pass the paremeter in that way because of this example:

http://www.suite101.com/content/how-to-create-a-simple-perl-ajax-application-a136201

Can anyone help??

Thanks a lot.


After the sugestion of Kinopiko, that makes sense, i have the following:

HTML-

function openFile(name){
            XMLHttp.open("GET", "/cgi-bin/readFile.pl?file="+encodeURI(name), true);
            XMLHttp.onreadystatechange = function() {
            if (XMLHttp.readyState == 4) {
                var container = XMLHttp.responseText.split("\n");
                if (container.length>0){
                    for ( i=0; i< container.length-1;i++){
                        document.getElementById("TxtArea").innerHTML += container[i] + " ";
                    }
                }
            }
            else{
                document.getElementById("TxtArea").innerHTML = "333";//XMLHttp.responseText;
            }
            }
            XMLHttp.send(null);
        }

Perl script:

#!c:/Perl/bin/perl

use strict;
use CGI qw/param/;  
use URI::Escape; 

print "Content-type: text/html\n\n";

my $file = param ('file'); 
$file = uri_unescape ($file); 

open (MYFILE, $file); 
    while (<MYFILE>) {
        chomp;
        print "$_\n";
}
close (MYFILE); 

Now i dont get error in javascript, but my XMLHttp.readyState is never 4, so i dont get the content of the file.

Maybe im using the encodeURI wrong??

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:12:02+00:00Added an answer on May 18, 2026 at 9:12 pm

    First of all you need to add a question mark:

    XMLHttp.open("GET", "/cgi-bin/readFile.pl?file="+name, true);
    

    Also you need to percent-encode “name” using encodeURI.

    On the Perl end, you can use a module like CGI to get the value of the file:

     use CGI qw/param/;
     my $file = param ('file');
    

    Then

     use URI::Escape;
     $file = uri_unescape ($file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having been a PHP developer on LAMP servers for quite a while, is there
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having worked with Classic ASP for about 2 years now by creating a few
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
Having to upgrade a database schema makes installing a new release of software a
Having a problem getting a TreeView control to display node images. The code below
Having programmed through emacs and vi for years and years at this point, I
Having integrated merb_auth_password_slice as per the README, I can successfully login as redirect_after_login is
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.