1

I'm doing ajax query

$.ajax({
    url: (some url),
    dataType: "json",
    error: function(xhr, textStatus, errorThrown) {
        (error handler)         
    },
    data : requestData,
    success: function(data) {
        (success handler)
    }
});

Works perfectly on Opera/Firefox/Webkit browsers. However when using IE and having requsestData containing some strings with non ascii characters (e.g. ł), error is returned and xhr status is 12031. Note that even replacing url to some existing document does not give 404 status (it does however in Opera etc.), so I think query isn't executed at all.

About mentioned duplicate: unfortunately it did not help me. Tried encodeURIComponent without result (and no wonder, cause jquery automatically does that when object is passed to requestData). Even hardcoded the query (passed as string) but it does not work too.

UPDATE: Query will work with non ascii data if it is cached in IE. That means I can copy prepared XHR url, paste it into another IE tab, then refresh the original page with ajax and receive no error.

UPDATE again: Fixed. What wasn't encoded properly was the referer url given in ajax query. It contained hash with non ascii character (however if cached, worked ok). Thank you for your efforts.

rds
  • 26,253
  • 19
  • 107
  • 134
konrad.kruczynski
  • 46,413
  • 6
  • 36
  • 47
  • Possible duplicate of http://stackoverflow.com/questions/2473316/jquery-ajax-is-not-sending-utf-8-to-my-server-only-in-ie ? – James Sumners Jan 28 '11 at 00:06
  • Linked question has more immediate solution, recommended, but not a duplicate. – Luka Ramishvili Jun 25 '12 at 08:39
  • possible duplicate of [How to correct character encoding in IE8 native json?](http://stackoverflow.com/questions/2570757/how-to-correct-character-encoding-in-ie8-native-json) – rds Mar 04 '13 at 14:52
  • By definition, if you use dataType=json, it's not ajax. I will edit the title – rds Mar 04 '13 at 14:53

1 Answers1

1

Remember your Ajax call must conform to UTF8 since you are not specifying the charset then it is the default.

That character is not acceptable in UTF8 and you have to encode it yourself. True, some browsers probably do it for you but basically you need to do it yourself in IE.

Aliostad
  • 80,612
  • 21
  • 160
  • 208
  • Well, did you mean setting content type to application/x-www-form-urlencoded;charset=utf-8? Did not help unfortunately. – konrad.kruczynski Jan 28 '11 at 00:14
  • 1
    No, UTF8 is already assumed. You are responsible for making sure the URL is encoded as UTF8. "ł" is not a valid UTF8 character and must be encoded as 2 or 3 bytes in UTF8 which you have to do it yourself. – Aliostad Jan 28 '11 at 00:17
  • Well, ł is valid UTF8 character encoded as two bytes and it is encoded properly (I can literally insert it into requestData using key=value format as %C5%82 and it does not work too). Besides AFAIK jquery encodes requestData in object form to utf8 anyway. – konrad.kruczynski Jan 28 '11 at 00:28