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 8414347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:08:45+00:00 2026-06-10T01:08:45+00:00

I have looked through several question about AJAX and character encoding, but I can

  • 0

I have looked through several question about AJAX and character encoding, but I can only seem to find questions about the response’s encoding, but not where the data sent to the server’s encoding.

I am sending a form serialized using jQuery to the server. PHP then saves this form’s fields to a database. The database uses latin1-swedish-ci. The page with the form uses iso-8859-1.

When I do this by using AJAX to send the data to the server, characters like “ get converted to “ on the way to the server, and get saved in the database as such. When I skip the AJAX and use a normal html form submit, the characters turn out fine in the database.

It is obvious that the jQuery serialization of the form data and the AJAX submission are what’s causing the characters to get mangled, but how can I fix this? I have tried changing the contentType of the AJAX call. I have tried using iconv() to convert the characters server side, which causes errors or incorrect translations. I have tried to use utf8_decode() server side, but this converts it into a question mark. I cannot change the output pages to UTF-8 encoding, because this causes other problems with other content on these pages. Ideally the solution would prevent the characters from being saved in the database wrong in the first place, as would happen with a normal html form submit. Any ideas on how to solve this?

javascript that sends the form to the server:

BlogEditForm.prototype.save = function() {
    var self = this;
    $.ajax( {
        type: 'POST',
        url: 'blog_edit_ajax.php',
        dataType: 'json',
        data: self.dialog.find( 'form' ).serialize(),
        success: function( response ) {
            self.processSaveResponse.call( self, response );
        }
    } );
};
  • 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-06-10T01:08:46+00:00Added an answer on June 10, 2026 at 1:08 am

    Seems that Javascript’s encodeURIComponent() encode characters differently than an actual form submition. Ended up re-writing javascript encodeURIComponent function to solve this… Not the most performant solution, but no other solutions presented themselves:

    var encodeURIComponent = ( function() {
        var encodeURIComponentOriginal = encodeURIComponent;
        return function ( input ) {
            var toReplace = [
                '%E2%80%9A',
                '%E2%80%A6',
                '%E2%80%98',
                '%E2%80%99',
                '%E2%80%9C',
                '%E2%80%9D',
                '%E2%80%93',
                '%E2%80%94',
                '%E2%84%A2',
                '%C2%A9',
                '%C2%AE',
            ];
            var replaceWith = [
                '%82', // ‚
                '%85', // …
                '%91', // '
                '%92', // '
                '%93', // "
                '%94', // "
                '%96', // –
                '%97', // —
                '%99', // ™
                '%A9', // ©
                '%AE', // ®
            ];               
    
            var output = encodeURIComponentOriginal( input );
    
            var length = toReplace.length;
    
            for ( var i = 0; i < length; i++ ) {
                var regexp = new RegExp( toReplace[i], 'g' );
                output = output.replace( regexp , replaceWith[i] );
            } 
    
            return output;
        };
    } )();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok.. I have looked through this site and just can't seem to find the
I've looked through the various questions on unit testing but can't find one that
I've looked through several posts but I haven't quite found any answers that have
I've looked through several posts on StackOverflow, but haven't been able to find an
I have looked through several sites for any useful documentation and have come up
I have looked through the solutions on stackoverflow and none of them seem to
I seem to have looked through many solution on here and the web and
I've downloaded the Windows Media Center SDK and have looked through the documentation, but
i know, similar questions have been asked, and i've already looked through everything i
I looked through previous questions to this effect, but my situation is slightly different...

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.