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

  • SEARCH
  • Home
  • 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 662425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:22:37+00:00 2026-05-13T23:22:37+00:00

I have encountered a weird situation while updating/upgrading some legacy code. I have a

  • 0

I have encountered a weird situation while updating/upgrading some legacy code.

I have a variable which contains HTML. Before I can output it, it has to be filled with lots of data. In essence, I have the following:

for my $line (@lines) {
    $output = loadstuff($line, $output); 
}

Inside of loadstuff(), there is the following

sub loadstuff {
    my ($line, $output) = @_;
    # here the process is simplified for better understanding.
    my $stuff = getOtherStuff($line);
    my $result = $output.$stuff;
    return $result;
}

This function builds a page which consists of different areas. All area is loaded up independently, that’s why there is a for-loop.

Trouble starts right about here. When I load the page from ground up (click on a link, Perl executes and delivers HTML), everything is loaded fine. Whenever I load a second page via AJAX for comparison, that HTML has broken encoding.

I tracked down the problem to this line my $result = $output.$stuff. Before the concatenation, $output and $stuff are fine. But afterward, the encoding in $result is messed up.

Does somebody have a clue why concatenation messes up my encoding? While we are on the subject, why does it only happen when the call is done via AJAX?

Edit 1

The Perl and the AJAX call both execute the very same functions for building up a page. So, whenever I fix it for AJAX, it is broken for freshly reloaded pages. It really seems to happen only if AJAX starts the call.

The only difference in this particular case is that the current values for the page are compared with an older one (it is a backup/restore function). From here, everything is the same. The encoding in the variables (as far as I can tell) are ok. I even tried the Encode functions only on the values loaded from AJAX, but to no avail. The files themselves seem to be utf8 according to “Kate”.

Besides that, I have a another function with the same behavior which uses the EXACT same functions, values and files. When the call is started from Perl/Apache, the encoding is ok. Via AJAX, again, it is messed up.

I have been examinating the AJAX Request (jQuery) and could not find anything odd. The encoding seems to be utf8 too.

  • 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-13T23:22:38+00:00Added an answer on May 13, 2026 at 11:22 pm

    A colleague of mine found the answer to this problem. It really had something to do with the fact that AJAX started the call.

    The file structure is as follows:

    1 Handler, accessed by Apache
    1 Handler, accessed by Apache but who only contains AJAX responders. We call it the AJAX-Handler
    1 package, which contains functions relevant for the entire software, who access yet other packages from our own Framework

    Inside of the AJAX-Handler, we print the result as such

    sub handler {
        my $r = shift; 
        # processing output   
        $r->print($output);
        return Apache2::Const::OK;
    }
    

    Now, when I replace $r->print($output); by print($output);, the problem disappears! I know that this is not the recommended way to print stuff in mod_perl, but this seems to work.

    Still, any ideas how to do this the proper way are welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered some strange Perl behavior: using a Posix character class in a
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load : I have
i have encountered a really weirdest bug in eclipse, i would love if someone
I have run into a weird necessity to make a certain window in the
I am newbie to ajax here and I know somebody would have encountered this
I am currently trying to code my own JS drag and drop script (out
Whats going on is i need to draw a black rectangle over the image.
I'm kinda new to Lua (not really done much with it yet) and I'm

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.