Skip to main content

Bug Tracker

Side navigation

#11930 closed bug (invalid)

Opened June 19, 2012 02:54AM UTC

Closed June 19, 2012 06:56PM UTC

Ajax POST is encoded in UTF-16

Reported by: soren121@sorenstudios.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

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() {
    $('#notifybox').slideUp('normal').empty();
    var inputs = [];
    $('.cf', this).each(function() {
        if($(this).is(':checkbox') && $(this).is(':not(:checked)')) {
            void(0);
        }
        else {
            inputs.push(this.name + '=' + escape(this.value));
        }
    })
    jQuery.ajax({
        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");
                }
                $('#title').val('');
                $('#wysiwyg').cleditor()[0].clear();
            }
            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.

Attachments (0)
Change History (4)

Changed June 19, 2012 03:14AM UTC by soren121 <soren121@sorenstudios.com> comment:1

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.

Changed June 19, 2012 03:16AM UTC by soren121 <soren121@sorenstudios.com> comment:2

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/

Changed June 19, 2012 06:36PM UTC by soren121 <soren121@sorenstudios.com> comment:3

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

Changed June 19, 2012 06:56PM UTC by mikesherov comment:4

resolution: → invalid
status: newclosed