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 am debugging some code and have encountered the following SQL query (simplified version):
My coworker and I have encountered a nasty situation where we have to use
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
I have encountered a rather odd error that I do not understand. I created
I have encountered odd behavior when using document.getElementById tonight. Duplicated in Firefox 3 and
I have encountered a problem that I have not come accross yet when setting
So far I have encountered adjacency list, nested sets and nested intervals as models
I am moving from classic ASP to ASP.NET and have encountered what many of
I'm migrating a TSQL stored procedure to PL/SQL and have encountered a problem -

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.