November 12th, 2007 02:37 PM
#1
encoding problem
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
November 12th, 2007 03:59 PM
#2
Re: encoding problem
When you send the contentType header, make sure you declare a character set that is compatible with Arabic. I believe UTF-8 contains Arabic.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 13th, 2007 01:31 AM
#3
Re: encoding problem
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.
November 13th, 2007 07:03 AM
#4
Re: encoding problem
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...
PHP Code:
header ( 'Content-Type: text/html; charset=utf-8' );
Second, You might need to declare the Content-type header in the AJAX when you send it.
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);
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 14th, 2007 12:52 AM
#5
Re: encoding problem
Dear Sir,
Thanx for your reply.
still i am facing the same problem.
my php and ajax code :
1. file1.php
PHP 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();'>" ;
?>
2. savedata.php
PHP 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 ;
?>
3.file3.js
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;
}
}
e.g.
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.
Last edited by PeejAvery; November 14th, 2007 at 06:45 AM .
Reason: Added code tags.
November 14th, 2007 07:20 AM
#6
Re: encoding problem
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.
Attached Files
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 14th, 2007 12:21 PM
#7
Re: encoding problem
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.
November 15th, 2007 09:02 AM
#8
Re: encoding problem
The following also works fine for me.
arabic.html
Code:
<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>
test.php
PHP Code:
<?php
header ( 'Content-Type: text/html; charset=utf-8' );
echo $_GET [ 'x' ];
?>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 15th, 2007 01:32 PM
#9
Re: encoding problem
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.
Last edited by farukcse; November 15th, 2007 at 01:35 PM .
November 15th, 2007 02:02 PM
#10
Re: encoding problem
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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 15th, 2007 04:32 PM
#11
Re: encoding problem
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
November 15th, 2007 05:27 PM
#12
Re: encoding problem
Read my last 2 posts. I already told you that it works.
Last edited by PeejAvery; November 15th, 2007 at 06:55 PM .
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
November 16th, 2007 01:00 PM
#13
Re: encoding problem
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
November 16th, 2007 01:37 PM
#14
Re: encoding problem
You're welcome. Good luck with the rest!
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
Bookmarks