Dear Sir,
i am facing a encoding problem in AJAX , it seems that it doesnt support multilanguage , i m trying to display Arabic text and i got '????'
how can i solve this problem?please try to send a reply to me.
Regards,
Faruk Chowdhury
Printable View
Dear Sir,
i am facing a encoding problem in AJAX , it seems that it doesnt support multilanguage , i m trying to display Arabic text and i got '????'
how can i solve this problem?please try to send a reply to me.
Regards,
Faruk Chowdhury
When you send the contentType header, make sure you declare a character set that is compatible with Arabic. I believe UTF-8 contains Arabic.
Dear Sir,
i added chracter set=utf-8 to both of my php file. but still am getting the same problem i.e i can't see my arabic characters. so can you tell me the way or code to set character set in javascript file for handling ajax request for sending data to php file .
[code]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
Regards,
Faruk Chowdhury.
I said, when you send the headers. Declaring them in the client-side documents isn't enough.
First, you need to declare them in any server-side document you are using. For PHP...
Second, You might need to declare the Content-type header in the AJAX when you send it.PHP Code:
header('Content-Type: text/html; charset=utf-8');
Code:obj.open('POST', url, true);
obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
obj.setRequestHeader('Content-length', parameters.length);
obj.setRequestHeader('Connection', 'close');
obj.send(parameters);
Dear Sir,
Thanx for your reply.
still i am facing the same problem.
my php and ajax code :
1. file1.php
2. savedata.phpPHP Code:
<?php
header('Content-Type: text/html; charset=utf-8');
?>
<?php
echo "<form name='form1'>
Plate No:<input type='text' name='plate_no1' size = 1 maxlength =1>
<input type='text' name='plate_no2' size = 1 maxlength =1>
<input type='text' name='plate_no3' size = 1 maxlength =1>
<input type='text' name='plate_no4' size = 1 maxlength =1>
<input type='text' name='plate_no5' size = 1 maxlength =1>
<input type='text' name='plate_no6' size = 1 maxlength =1>
<input type='text' name='plate_no7' size = 1 maxlength =1>
<input type='button' name = 'save' id='save' value='Save Data' onclick='SaveData();'>";
?>
3.file3.jsPHP Code:
<?php
header('Content-Type: text/html; charset=utf-8');
?>
<?php
$plate_no = $_GET['plate_no1']." ".$_GET['plate_no2']." ".$_GET['plate_no3']." ".$_GET['plate_no4']." ".$_GET['plate_no5']." ".$_GET['plate_no6']." ".$_GET['plate_no7'];
echo $plate_no;
?>
e.g.Code:function SavaData() {
var plate_no1 = document.form1.plate_no1.value;
var plate_no2 = document.form1.plate_no2.value;
var plate_no3 = document.form1.plate_no3.value;
var plate_no4 = document.form1.plate_no4.value;
var plate_no5 = document.form1.plate_no5.value;
var plate_no6 = document.form1.plate_no6.value;
var plate_no7 = document.form1.plate_no7.value;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="save_policy.php"
url=url+"?plate_no1="+plate_no1+ "&plate_no2="+plate_no2+ "&plate_no3="+plate_no3+ "&plate_no4="+plate_no4+ "&plate_no5="+plate_no5+ "&plate_no6="+plate_no6+ "&plate_no7="+plate_no7
url=url+"&sid="+Math.random();
soapRequestStr='<?xml version="1.0" encoding="utf-8"?>';
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open('GET',url,true);
//xmlHttp.open("GET",url,true);
xmlHttp.setRequestHeader('Content-type', 'text/xml;charset=utf-8');
xmlHttp.setRequestHeader('Content-length',soapRequestStr.length);
xmlHttp.setRequestHeader('soapRequestStr', 'close');
xmlHttp.send(soapRequestStr);
//xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint2").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
}
if i send 9 2 3ص ص ص then i get the out pt from file2.php as 9 2 3 � �tml>
if i set POST method in ajax and modify the varaible of file2.php with $_POST[''] then i get notice with alll of variable undefined..
So. please can you tell me where is my error or how can i solve this?
Please reply .
Thanks in Advance.
Regards,
Faruk Chowdhury.
I have done much testing and so long as I supply the proper header in the PHP file, it works for me. Try the following attached zip file.
Dear Sir,
According your .zip files i used these files.in your file i can get arabic characters from arabic.php using ajax to arabic.html and inthat case there is no problem. but when i want to send arabic chracter form arabic.html to arabic.php using ajax then i get the output as 9 2 3 ? ? ? at arabic.html file. this is requirement for me. so please can you help me to send arabic characters from arabic.html to arabic.php according to your example?
please try to send a reply to me.
Thanks in advance.
Regards,
Faruk Chowdhury.
The following also works fine for me.
arabic.html
test.phpCode:<html>
<body>
<script type="text/javascript">
var AJAX = {
initialize: function(){
var xmlHTTP;
try{xmlHTTP = new XMLHttpRequest();}
catch(e){
try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){
try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHTTP;
},
get: function(url, func){
var obj = this.initialize();
obj.open('GET', url, true);
obj.send(null);
obj.onreadystatechange = function(){
if(obj.readyState == 4){
func(obj.responseText);
}
}
}
}
function getUpdate(txt){
document.getElementById('getReturn').innerHTML = txt;
}
</script>
<input type="text" id="test" name="test" value="blah" onkeyup="AJAX.get('test.php?x=' + this.value, getUpdate)" />
<div id="getReturn"></div>
</body>
</html>
PHP Code:
<?php
header('Content-Type: text/html; charset=utf-8');
echo $_GET['x'];
?>
Dear Sir,
Actually your code works very well if i type english characters in the input box as input for the text box . but if i type arabic character then it's output comes as ???.
i.e if i type س س س س س then it its comes as ? ? ? ? ?. please try to check your code with my example. i am facing this problem.
Please reply me.i need solution for this problem.
Again thanks for your cooperation.
Regards,
Faruk Chowdhury.
I tested my example on multiple machines, servers, and OSs. It works. So, that means that it is something on your end. Possibly the browser you are using. Have you tried using IE, Firefox, and Safari?
Dear Sir,
Have you checked with arabic characters as input? i.e. send س سص فخ to test.php file and get the output at arabic.html.
i tested with IE,mozila . this is same problem i.e i got the error output as a ? ? ? for input text arabic characters.
The problem is only with arabic characters,.
Regards,
Faruk Chowdhury
Read my last 2 posts. I already told you that it works.
Dear Sir,
Many Many thanx for your cooperation. Actualy your code is working using this code
[code]
AJAX.get('test.php?x=' + encodeURIComponent(this.value), getUpdate).
now this is working well for arabic characters.
Again thanx to you for helping me to solve this problem.
Regards,
Faruk Chowdhury
You're welcome. Good luck with the rest! :wave: