Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11930 closed bug (invalid)

Ajax POST is encoded in UTF-16

Reported by: soren121@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


When I submit Chinese characters (in this example, 中文) via an .ajax() POST, jQuery appears to encode the data in UTF-16.

I've intercepted the POST headers with Firebug, which says that jQuery sends those two characters as %u4E2D%u6587. That appears to be URL-encoded UTF-16. If I disable the jQuery AJAX and POST it normally through Firefox 13, Firefox sends %E4%B8%AD%E6%96%87, which is definitely URL-encoded UTF-8.

Here's the jQuery code in question (ripped from my blog software LightBlog):

$('#create').submit(function() {
    var inputs = [];
    $('.cf', this).each(function() {
        if($(this).is(':checkbox') && $(this).is(':not(:checked)')) {
        else {
            inputs.push(this.name + '=' + escape(this.value));
        data: inputs.join('&'),
        type: "POST",
        url: this.getAttribute('action'),
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        timeout: 2000,
        error: function() {
            $('#notifybox').text('Failed to submit <?php echo $type; ?>.').css("background","#E36868").css("border-color","#a40000").slideDown("normal");
        success: function(json) {
            var r = jQuery.parseJSON(json);
            if(r.result == 'success') {
                if(r.showlink == true) {
                    $('#notifybox').html('<?php echo ucwords($type) ?> created. | <' + 'a href="' + r.response + '">View <?php echo $type ?></' + 'a>').slideDown("normal");
                else {
                    $('#notifybox').html('<?php echo ucwords($type) ?> created.').slideDown("normal");
            else {
                $('#notifybox').text('Failed to submit <?php echo $type; ?>; ' + r.response).css("background","#E36868").css("border-color","#a40000").slideDown("normal");
    return false;

Stack Overflow (link to my question at SO) told me to report this here, as it appears to be a bug in jQuery. It happens in every major browser, and I've set the meta tags to UTF-8, sent the headers as UTF-8 and such; none of that helps.

Change History (4)

comment:1 Changed 7 years ago by soren121 <soren121@…>

I apologize for the block of code in the ticket; I didn't see the jsFiddle notice until after I submitted it, and I can't edit it now.

Here's a link to the code on jsFiddle: http://jsfiddle.net/pJgyu/25799/

You'll need to have something open to intercept the POST data, like Firebug, or Chrome Inspector.

comment:2 Changed 7 years ago by soren121 <soren121@…>

It's probably obvious that I never submit bugs, and I apologize for spamming, but here's a corrected link: http://jsfiddle.net/pJgyu/25800/

comment:3 Changed 7 years ago by soren121 <soren121@…>

Please mark this ticket invalid. The problem lies in escape(), and has nothing to do with jQuery. My apologies.

comment:4 Changed 7 years ago by mikesherov

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.