Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error on german character in POST

1 view
Skip to first unread message

Jose Enrique

unread,
Jul 21, 2008, 6:35:48 AM7/21/08
to
Hello!
I have a problem when my javascript receives german characters. They appears
as '?' in the responseText.
I have no access to the server where I make the post request. It is from
another company and I cannot change anything.

I'd be very grateful if anyone could help me.

My code is the following:

function makePOSTRequest(url, parameters) {

http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
try {

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
//alert("Permission UniversalBrowserRead denied.");
}
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/plain; charset=ISO-8859-2');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}

function ValidarCuenta(paginavalidacion)
{

var valorcuenta=document.Form1.Knr.value;
var codigobanco=document.Form1.Blz.value;

var poststr = "knr=" + encodeURIComponent(valorcuenta) +
"&blz=" + encodeURIComponent(codigobanco);

makePOSTRequest(paginavalidacion, poststr);

return true;

}


Martin Honnen

unread,
Jul 21, 2008, 8:27:10 AM7/21/08
to
Jose Enrique wrote:

> I have a problem when my javascript receives german characters. They appears
> as '?' in the responseText.

Can you check how
http_request.getAllResponseHeaders()
looks? Does the server send a HTTP Content-Type header with a charset
parameter? Is there a problem with those characters with both Firefox
and IE or only IE?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jose Enrique

unread,
Jul 21, 2008, 8:37:10 AM7/21/08
to
Only fail in IE

"Martin Honnen" <maho...@yahoo.de> escribió en el mensaje
news:ejOTc0y6...@TK2MSFTNGP02.phx.gbl...

Jose Enrique

unread,
Jul 21, 2008, 8:42:04 AM7/21/08
to
If I look the getallresponseheaders before I get responsetext, I get the
following information:

server: apache/1.3.41 (Unix)
x powered-by: PHP/5.2.6
transfer-encoding: chunked
content-type:text/html

"Martin Honnen" <maho...@yahoo.de> escribió en el mensaje
news:ejOTc0y6...@TK2MSFTNGP02.phx.gbl...

Martin Honnen

unread,
Jul 21, 2008, 8:58:59 AM7/21/08
to
Jose Enrique wrote:
> Only fail in IE

There is not much you can do. The server needs to send the HTTP
Content-Type header with a charset parameter e.g.
Content-Type: text/plain; charset=ISO-8859-1
so that the receiving code is able to properly decode the response body.
If there is no charset parameter then MSXML used by IE assumes UTF-8.

Jose Enrique

unread,
Jul 21, 2008, 9:14:53 AM7/21/08
to
I think the charset is ISO-8859-2 because the code works well in firexfox
but it doesn't work in IE6.

How I can make somethig similar to

http_request.overrideMimeType('text/plain; charset=ISO-8859-2') ?

I have use

http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded; charset=ISO-8859-2");

but it doesn't work.


"Martin Honnen" <maho...@yahoo.de> escribió en el mensaje

news:OAmUOGz6...@TK2MSFTNGP03.phx.gbl...

Martin Honnen

unread,
Jul 21, 2008, 9:39:03 AM7/21/08
to
Jose Enrique wrote:
> I think the charset is ISO-8859-2 because the code works well in firexfox
> but it doesn't work in IE6.
>
> How I can make somethig similar to
>
> http_request.overrideMimeType('text/plain; charset=ISO-8859-2') ?

You can't as far as I know, you have to make the server send the charset
parameter.

> I have use
>
> http_request.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded; charset=ISO-8859-2");
>
> but it doesn't work.

That sets the request header to tell the server how your _request body_
is encoded, it does not help for decoding the _response body_.

José Enrique Aguado Gijón

unread,
Jul 21, 2008, 2:08:28 PM7/21/08
to
Sorry for not answering before. I go out from work at 15:00. Now I'm in
home.

Then do you think there is something I can do to receive well this
characters?

"Martin Honnen" <maho...@yahoo.de> escribió en el mensaje

news:OV75mcz6...@TK2MSFTNGP04.phx.gbl...

Martin Honnen

unread,
Jul 22, 2008, 7:29:05 AM7/22/08
to
José Enrique Aguado Gijón wrote:

> Then do you think there is something I can do to receive well this
> characters?

Unless you can change the server-side code to make sure it sends the
HTTP response header with the used charset I don't know how to solve the
problem.

Anthony Jones

unread,
Jul 22, 2008, 7:53:19 AM7/22/08
to
"José Enrique Aguado Gijón" <jeag...@wanadooadsl.net> wrote in message
news:OOMKE116...@TK2MSFTNGP04.phx.gbl...


Probably the best solution is to have your site make the request to the
third party site on the clients behalf. It can then forward the
responseStream or body but set the ContentType and CharSet values correctly.


--
Anthony Jones - MVP ASP/ASP.NET


0 new messages