user274069
user274069

Reputation: 217

jquery Ajax response char problem

Through jquery ajax function, i am retreving data from server. everything seems fine but some german character displaying as '?' , Can anyone suggest me how to resolve this problem.

$.ajax({
    type: "GET",
    cache: false,
    dataType: "json",
    contentType: "application/json; charset=iso-8859-1",
    url: url,
    async: true,
    timeout: timeOut,
    success: function (data, status)
    {
    if (status == "success")
    {
    displayHotelDetails(data);
    }
    }
    });

Upvotes: 1

Views: 18518

Answers (2)

Oleg
Oleg

Reputation: 221997

The contentType parameter say how the data parameter (which you not use) will be encoded when the data are sent to the server. Moreover in the part of the jQuery.ajax documentation which describes contentType parameter you will find:

Data will always be transmitted to the server using UTF-8 charset; you must decode this appropriately on the server side.

So you should probably examine Content-Type HTTP header of the server response. You can use Fiddler or Firebug.

You can explicitly set the in the HTTP header something like

response.setHeader("Content-Type", "application/json; charset=ISO-8859-1");

or

response.setContentType("application/x-json");
response.setCharacterEncoding("ISO-8859-1");

The call should be done on the server and so depend of the technology which you use.

Upvotes: 1

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21366

This will help

Jquery: ajax post and encoding

Upvotes: 0

Related Questions