-
March 21st, 2008, 03:12 PM
#1
AJAX and special characters
hi everyone.
Am trying to get some data (in french) from a database, but the special characters like "é" are getting replaced by question marks. I have been able to find a way in mozilla using
xmlHttp.overrideMimeType('text/xml; charset=iso-8859-1');
but it is not working in IE7 and IE6.
here are the codes :
Code:
function showArticles(rubrique)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="displayTable.php";
url=url+"?r_id="+rubrique;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("dynamicTable").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
xmlHttp.overrideMimeType('text/xml; charset=iso-8859-1'); //NO CHARACTER PROBLEM IN MOZILLA
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
//xmlHttp.overrideMimeType('text/xml; charset=iso-8859-1'); // THIS DOES NOT WORK, I"VE COMMENTED IT
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Last edited by PeejAvery; March 22nd, 2008 at 04:12 PM.
Reason: Added code tags.
-
March 22nd, 2008, 04:24 PM
#2
Re: AJAX and special characters
I have found with AJAX, that if the actual file is not saved in a specific file type, then it can return invalid characters rather than the special characters. Are you sure the file is saved as iso-8859-1?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 23rd, 2008, 03:22 AM
#3
Re: AJAX and special characters
Yes. Both my files are saved with iso-8859-1. Shouldn't it have something to do with xmlHttp? because when i override the mime type for mozilla, it works for that browser.
I dont know if anyone knows an alternative to eliminate this problem.
The file sending the request also has special characters in it. They are displayed correctly.
When i run the file being called individually, it also give the correct characters. The problem is only when the content of the file being called is being passed to the requesting file and displayed in a div. Here the special characters are wrong.
Last edited by PeejAvery; March 24th, 2008 at 08:43 AM.
Reason: Merged two posts.
-
March 23rd, 2008, 06:36 AM
#4
Re: AJAX and special characters
Problem solved. It was indeed a problem with charset.
-
May 12th, 2009, 06:56 AM
#5
Re: AJAX and special characters
We are also facing simliar kind of problem, not able to send the special chars in request. Yashin mentioned that the problem is solved with charset. Can you provide your code here which may help us to solve our issue.
-
May 12th, 2009, 08:08 AM
#6
Re: AJAX and special characters
The problem is simply crossing character sets. Just make sure that the character set you are attempting to output is the same as the saved file that is being read.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|