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;
}
> 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/
"Martin Honnen" <maho...@yahoo.de> escribió en el mensaje
news:ejOTc0y6...@TK2MSFTNGP02.phx.gbl...
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...
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.
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...
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_.
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...
> 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.
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