Ticket #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: | ||
| Blocking: | Blocked by: |
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.
Change History
comment:2 Changed 12 months 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/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.