Link to home
Start Free TrialLog in
Avatar of shmulik15
shmulik15

asked on

Hebrew with JavaScript server-side

Hello,

I am programming ASP using JavaScript as my server-side language.
I have the following code:

<%
Response.CharSet="windows-1255"

var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET", "http://www.simil.co.il/", false);
xmlHttp.send();
xmlDoc = xmlHttp.responseText;

Response.Write(xmlDoc);
%>

And I get the Hebrew (the page is in Hebrew) as ?? ??? ?? ?

How can this be solved?

Thanks.
Avatar of stanscott2
stanscott2

Whenever you send an XMLHTTPRequest, you need to specify a content-type, if you don't, UTF-8 is used.

In the line just following your xmlHttp.open code, enter this:

xmlHttp.setRequestHeader('text/xml', 'Windows-1255');

Avatar of Zvonko
Does this help:

   Response.Write(Server.HTMLEncode(xmlDoc));


Avatar of shmulik15

ASKER

Thanks guys, but neither worked.

xmlHttp.setRequestHeader('text/xml', 'Windows-1255'); <- Returns "Unspecified error "
HTMLEncode returns it as Gibberish as well.
Stupid question: do you have correct displayed alefbet characters on the same page when you see question marks?
Can you see the page correct when you enter the simil URL in browser address bar?
Zvonko: Yes, Simil is a webpage that I own and it is displayed just fine, and yes, I can indeed see Hebrew on the page with the XMLHTTP Request.
Sorry, let's try again:

xmlHttp.setRequestHeader("Content-Type:text/html"; charset:ISO-8859-1");

I believe that the unicode character set supports Hebrew.  If not, try replacing "ISO-8859-1" with "Windows-1255".
stanscott2:
This returns an error as well.
Is here something for you: http://www.yuro2u.com/guides/XMLHTTP/
Thanks zvonko, but the example is in VBS, I need it in JS (and I don't know how to make it).
Any help with that would be appreciated.
There is no example that you could directly use. The link was more to enlight the background of the code page problem.
If you have any VB example I can easuly convert it for you to JScript.

By the way, my alias is &#1494;&#1456;&#1488;&#1461;&#1489; ;-)
Well, it says the problem with Hebrew is that it has to be encoded into UTF-8

This function should do it:

Function AsciiToUnicode(ByRef pstrAscii)
            For llngIndex = 1 To LenB(pstrAscii)
                        lstrUnicode = lstrUnicode & Chr(AscB(MidB(pstrAscii, llngIndex,1)))
            Next
            AsciiToUnicode = lstrUnicode
End function
(taken from the article you linked to)

OK, give me a second...
Here we go:

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<div id="nickname">&#1494;&#1456;&#1488;&#1461;&#1489;</div>
<script>

function AsciiToUnicode(pstrAscii){
  var lstrUnicode = "";
  for(var i=0;i<pstrAscii.length;i++){
    lstrUnicode += String.fromCharCode(pstrAscii.charCodeAt(i));
  }
  return lstrUnicode;
}


alert(AsciiToUnicode(document.getElementById("nickname").innerHTML));
</script>
</body>
</html>

Ugh, the article said it should do the trick, which it didn't.
Any ideas would be appreciated.

By the way - Thank you very much for all the effort, Zvonko.
OK, let us start over.
When I store the browser html page from http://www.simil.co.il/ to local file and look at it then I see alefbet because the page encoding is switched (automaticaly) to "Hebrew (Windows)"
By the way, the Goggle ad on that page is then Giberisch.
Now, what page encoding schema does you browser show and use when you look at the page with or without the injected html?

The encoding is(was) Windows-1255 and I tried the UTF-8 method later. Neither worked.
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sure, sending as email.
Hi people - what was the result of this exercise? Would you please share?

alert("\u05DD\u05D5\u05DC\u05E9")
Uhps, sorry, I solved it but missed to update here.
Give me a second please...
OK, this is the working example:



<%@LANGUAGE="JavaScript"%>
<%

var xmlHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1");

xmlHttp.open("GET", "http://www.mechon-mamre.org/p/pt/pt3001.htm", false);

xmlHttp.send();
xmlDoc = xmlHttp.responseText;

Response.Write('<base href="http://www.mechon-mamre.org/p/pt/">');
Response.Write(xmlDoc);

%>