Salman Arshad
Salman Arshad

Reputation: 272426

Browser displays strange characters when data is loaded via AJAX, not otherwise

$.get("/ajax-terms.asp", function(d){
    $("#wrap-terms").html(d);
})

When the terms data is included directly into the document using "Response.Write" everything appears correctly, including these characters: and

When I request the same data via AJAX, strange symbols are returned by server (or may be the server sends the right thing but browser renders them incorrectly). This is the strange symbol:

Any workaround?

Edit: Here are the headers for the container page:

GET /register.html

Host: ********.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: ********

Date: Sat, 06 Nov 2010 06:08:45 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 38317
Content-Type: text/html
Cache-Control: private

The container page contains this line:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

This is the jQuery/Ajax request fired by the container page:

$.get("/ajax-terms.asp", function(d){
    $("body").append(d);
})

This is what I get:

GET /ajax-terms.asp

Host: ********.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://********.com/register.html
Cookie: ********

Date: Sat, 06 Nov 2010 06:12:53 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 23436
Content-Type: text/html
Cache-Control: private

The response seems to contain and correctly but not sure why it is rendered as .

Upvotes: 0

Views: 1413

Answers (1)

Robusto
Robusto

Reputation: 31913

It sounds like the AJAX getting sent by your server is encoded differently from what the browser is set to. Check the headers for the incoming AJAX.

Upvotes: 1

Related Questions