Link to home
Start Free TrialLog in
Avatar of LeGrandi
LeGrandiFlag for Spain

asked on

AJAX and HTML encoding problem

I have a problem with encoding with AJAX.

I am not using a framework, just standard javascript. Through AJAX I load a HTML file and display the responseText inside a div (innerHTML = req.responseText).

The problem is that it does not load a client-server request, but a regular HTML file, so the encoding goes crazy and things like á , é, í, etcetera are not displayed correctly. I would like to know if there is some way to indicate the XHMTLRequest object to load the response in a given encoding, or to give the HTML file that is loaded an specific header for the Ajax request to understand it correclty.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

It should display using the character set of the page that is loading it.  Is it the same as the page you are loading thru AJAX?  These pages are the most complete description of using AJAX that I have found:
Avatar of LeGrandi


Actually it works that way in Chrome, but not in Firefox or IE. How should I indicate in the html page which is loaded the charset?
Use this line in the header, preferably as the first line below <header>.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

Open in new window

It still doesn't work
Does the encoding on the original page and the AJAX page match?
The ajax, indeed, is not a Full page with <html></html> and <body></body>, but an HTML fragment and now has a <head></head> with the meta content-type inside
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

it definitely doesn't work, so I will html encode the conflictive characters which is far simpler.

Not total solution.