473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLHTTP

Hello,
I am working on a site which utilizes PHP/JS and the new found XMLHTTP
frenzy to update dynamically.
WHile the whole mechanism works beautifull, i can't get to display
greek Characters correct (They show up as ?).
I tried following solutions to set the XML:lang or simple lang
parameter in the div to el, but that didn't help.. Greek text in the
surrounding page is showing up correct..
Here is the code i am using:
The JS File
if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
xmlhttp = new XMLHttpRequest( );
}

function loadFragmentInT oElement(fragme nt_url, element_id) {
var element = document.getEle mentById(elemen t_id);
element.innerHT ML = 'Loading ...';
xmlhttp.open("G ET", fragment_url);
xmlhttp.onready statechange = function() {
if (xmlhttp.readyS tate == 4 && xmlhttp.status == 200) {
element.innerHT ML = xmlhttp.respons eText;
}
}
xmlhttp.send(nu ll);
}

The client PHP:
<?php
include ("../_mssqlconnect.p hp");
include ("get_login_dat a.php");
?>
<script>
function offerDetails(id )
{
loadFragmentInT oElement('sc_og details.php?ogi d='+id, 'ogDetails');
}
</script>

//......

?>
<span lang="el" id="ogDetails" align="left"></span>

The server PHP:
<?php
include ("../_mssqlconnect.p hp");

//.......

echo "<div lang=\"el\">
<table class='sp_table ' width=300 align=center>
<tr>
<td align=center><b >{here the greek Text which doesnt come
out right}<b></td>
</tr>
</table></div>";

ANy hints?
thanks

Jul 23 '05 #1
6 3070


Nemlah wrote:

I am working on a site which utilizes PHP/JS and the new found XMLHTTP
frenzy to update dynamically.
WHile the whole mechanism works beautifull, i can't get to display
greek Characters correct (They show up as ?). element.innerHT ML = xmlhttp.respons eText;


responseText is unreliable when it comes to encodings other than UTF-8
or UTF-16. So if you want to use responseText then make sure your PHP
page sends UTF-8 encoded text. Or do not use responseText but exchange
XML and use responseXML, then if your PHP page sends XML with the proper
XML declaration the XML parser should recognize the encoding and
properly decode characters. But XML parsers are only required to support
the encodings UTF-8 and UTF-16 thus if you want to make sure your page
works with as many browsers as possible then you should use one of those
encodings for your XML sent.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Hey thanks for the fast reply,
I read about the UTF-8 encoding of the strings sent via responseText,
and i hoped i could setRequestHeade r to the correct charset.. Doesn't
seem to work though..(unknow n exception error)
I am trying the XML approach you suggested. Actually i am writing
manually an XML string and echoing it. All i get so far though is a
[object] in IE and nothing in firefox.
Apparently the responseXML returns an Document object. How can i print
it? I am not really interested right now in XML magic, but if wrapping
the data in XML helps i am willing to do that..
Any further hints..?
Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Vasilis Dimos wrote:
Hey thanks for the fast reply,
I read about the UTF-8 encoding of the strings sent via responseText,
and i hoped i could setRequestHeade r to the correct charset.. Doesn't
seem to work though..(unknow n exception error)
I am trying the XML approach you suggested. Actually i am writing
manually an XML string and echoing it. All i get so far though is a
[object] in IE and nothing in firefox.
Apparently the responseXML returns an Document object. How can i print
it? I am not really interested right now in XML magic, but if wrapping
the data in XML helps i am willing to do that..
Any further hints..?
Thanks


I had a similar problem not long ago.
i past again some php code which should help you.

<?php
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
$xmlString .=
'<root><text xml:lang="de">U mlaute: ä, ö, ü</text></root>';
header('Content-Type: application/xml');
echo utf8_encode($xm lString);
?>

As you can see the xml string is build also manually, but is utf8
encoded before echoed.

In the Javascript again, you can access the responseXML object with the
normal W3C DOM Methods.

Have a look a this page for a good intro:
http://www.quirksmode.org/dom/intro.html
Jul 23 '05 #4


Vasilis Dimos wrote:

I read about the UTF-8 encoding of the strings sent via responseText,
and i hoped i could setRequestHeade r to the correct charset.. Doesn't
seem to work though..(unknow n exception error)


The PHP script needs to send UTF-8 encoded text so I am not sure what
you are trying to achieve with setRequestHeade r on the client.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5


Vasilis Dimos wrote:

I am trying the XML approach you suggested. Actually i am writing
manually an XML string and echoing it. All i get so far though is a
[object] in IE and nothing in firefox.


I do not speak Greek so I am relying on babelfish for this. It
translates English
Who is god?
to the following:
Î*οιος είναι Θεός;

Now assuming you are encoding your PHP pages as ISO-8859-7 which is an
8-bit encoding allowing you to use Latin letters and Greek letters you
could send your XML as ISO-8859-7 and then rely on the XML parser to
decode that. As said XML parsers do not need to understand that encoding
but my tests here with MSXML/IE 6, Mozilla and with Opera 8.00 beta show
they do understand that.
I have used the following PHP test page encoded as ISO-8859-7:

<?php
$text = 'Î*οιος είναι Θεός;';
$xmlSource = '<?xml version="1.0" encoding="ISO-8859-7"?>' . "\r\n";
$xmlSource .= '<text xml:lang="gr">' . $text . '</text>';
header('Content-Type: application/xml');
echo $xmlSource;
?>

Then client-side script reads the XML sent as follows:

function getText (url, callback) {
var httpRequest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest( );
}
else if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject(' Microsoft.XMLHT TP');
}
if (httpRequest) {
httpRequest.ope n('GET', url, true);
httpRequest.onr eadystatechange = function () {
if (httpRequest.re adyState == 4 && httpRequest.res ponseXML) {
var xmlDocument = httpRequest.res ponseXML;
if (xmlDocument.do cumentElement &&
xmlDocument.doc umentElement.fi rstChild) {
callback(xmlDoc ument.documentE lement.firstChi ld.nodeValue);
}
}
};
httpRequest.sen d(null);
}
}

function insertTextIntoB ody (text) {
var p;
if (document.creat eElement && (p = document.create Element('p'))) {
p.appendChild(d ocument.createT extNode(text));
document.body.a ppendChild(p);
}
}

getText('test20 04123101.php', insertTextIntoB ody);

and then the tested browsers show

Î*οιος είναι Θεός;

in the HTML page.
Or use the PHP extension iconv if you have that available
http://de3.php.net/manual/en/function.iconv.php
to convert your 8-bit PHP strings to UTF-8 as needed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #6


Hey Guys,
Thanks a lot for the answers. This is actually a lot more than I could
hope for. I will try this first thing in 2005. Happy new Year to all of
you.

Thanks Vasilis

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5554
by: fochie | last post by:
Greetings, I'm having a problem when I try to GET a file from my server via xmlhttp when using Mozilla. With IE I can get any type of file fine, get/display headers fine, etc. With Mozilla, using the same HTML/JS it always returns no data (xmlhttp.responseText is null). When I try to get headers using Mozilla or display the http status...
1
4910
by: Ike | last post by:
Ive copied an online example for writing out a php file, programmatically, then would like to re-display that data in a browswer window that automatically refreshes as the data file (getdata.php, which is the file I am programmatically rewriting to elsewhere) gets changed. I am trying to use AJAX and JSON to do this. I have copied an example...
5
2806
by: hatsumoto | last post by:
Hello, I create an ActiveXObject("Msxml2.XMLHTTP") from my HTML page to submit (i.e. post) XML to a server. I can see the content of the XML response via javascript alert(xmlhttp.responseText). Is there a way to display the content of xmlhttp.responseText on a new page?? I tried document.write(xmlhttp.responseText) but this does not...
9
2368
by: balakrishnan.dinesh | last post by:
hi friends, Exactly what i want to know is, In my product we are using xmlhttp request to retrive some data from the server, And Im using IE browser, its working fine in IE. Now i want to work with netscape,I dont know how to pass the xmlhttp request in Netscape. i got some code like below for netscape for xmlhttp var oXML=new...
13
25126
by: yawnmoth | last post by:
<http://www.quirksmode.org/book/printable/xmlhttp.txtshows two alternatives to Microsoft.XMLHTTP - Msxml2.XMLHTTP and Msxml3.XMLHTTP. If my understanding is correct, the different numbers refer to the version of Microsoft's XML parser and that Microsoft.XMLHTTP refers to the latest installed version. This makes me wonder why sites like...
1
3837
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function and send the item number to the xmlHttp and works awesome. Now I need to add an apply button next to it. so they can type in the complete number then...
3
2571
by: Andrewh | last post by:
Hi, I am having a bit of a problem with using xmlhttp. The code of the javascript file is shown below used in Windows XP. var xmlhttp = null; function SetURLDiv(url) { if (window.XMLHttpRequest) {
2
12451
by: trpost | last post by:
Is it possible to execute javascript as passed in xmlHttp.responseText Here is what I am doing: search.js var xmlHttp xmlHttp=GetXmlHttpObject() var url="search.php" xmlHttp.onreadystatechange=stateChanged
1
1488
by: StevenS | last post by:
Ok, I'm very new to AJAX programming, and fairly new to Javascript. (I was originally trained on low-level C programming.) I'm trying to build a simple AJAX routine in a file named ajax.js: var xmlReqs = new Array(); function CXMLHttp(cb,data,xmlHttp) { this.cb = cb; this.data = data; this.xmlhttp = xmlHttp; }
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.