Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Ajax - IE Microsoft.XMLHTTP responseText encoding problem
#1

[eluser]hashintosh[/eluser]
Good morning,
I have a problem with the variable responseText of the object Microsoft.XMLHTTP, that I use to load page subcontents through Javascript (Ajax).
When I use special characters (letters with accents, quotes, double quotes, etc.) these are renderized, under Internet Explorer, as unrecognized characters.

You can see the problem on this website, moving from one page to another one through the navigation menu (Home, L'azienda, I Nostri Vini):

-> http://apache.360solutions.it/js/

The first page that you load never has this problem, because it's loaded server side, and in this way there is no problem even under IE, but using Microsoft.XMLHTTP to load contents the problem appears (you can see small squares in the text, in several parts of the page).

In Firefox I could use the method overrideMimeType, but unfortunately IE doesn't support this method.

In php pages that represents the page contents, I set the Content-Type header in this way:

Code:
header("Content-type: text/html; charset=ISO-8859-1");

This is necessary to have those special characters recognized, both under FF and under IE.

I've tried several ways, even encoding the server response as if it was a query string, and then decoding through javascript, but it doesn't work, and I have really don't know what else to try to solve this problem.

Could someone, with more experience on Ajax, help me please?

Thank you very much!
Alessio
#2

[eluser]TheFuzzy0ne[/eluser]
Are you using GET or POST to retrieve your messages? I would suggest POST.
#3

[eluser]hashintosh[/eluser]
[quote author="TheFuzzy0ne" date="1234543062"]Are you using GET or POST to retrieve your messages? I would suggest POST.[/quote]

I'm using GET... You think that a POST request would solve my problem?
#4

[eluser]TheFuzzy0ne[/eluser]
It could do. There's only one way to find out. Smile

Another solution may be to use urlencode() and urldecode() on the server side, and encodeURI() and decodeURI() on the client side.
#5

[eluser]hashintosh[/eluser]
[quote author="TheFuzzy0ne" date="1234543521"]It could do. There's only one way to find out. Smile

Another solution may be to use urlencode() and urldecode() on the server side, and encodeURI() and decodeURI() on the client side.[/quote]


With urlencode server side and decodeURI client side I've already tried, but it doesn't work properly.

I'll try with a POST method, even if I don't understand why it should work differently from a GET request...

I'll post here the result as soon as I've tried.
In the meanwhile, thanx Smile
#6

[eluser]hashintosh[/eluser]
[quote author="TheFuzzy0ne" date="1234543062"]Are you using GET or POST to retrieve your messages? I would suggest POST.[/quote]

As suggested, I've tried to change the line
Code:
_httpReq.open('get', url);
with
Code:
_httpReq.open('post', url);
where _httpReq is the Miscrosoft.XMLHTTP object.

The result is the same, i still have the same encoding problem.

Any other idea?
#7

[eluser]TheFuzzy0ne[/eluser]
I'm not sure I understand where the problem is happening. Can you tell me which link I need to click on to see this, as the page seems to render fine for me.

EDIT: I am using IE7.
#8

[eluser]hashintosh[/eluser]
The problem is both under IE6 and IE7.

You should click for example on the link "L'Azienda": when the page loads, you will notice, in the text, some little squares, that are put by IE because it doesn't recognize the encoding of those characters (they should be letters with accents and double quotes).

If you open the same link with Firefox, you'll see that the problem doesn't exist.

Can you see it?
#9

[eluser]TheFuzzy0ne[/eluser]
No, I don't see it. Please see [url="http://www.freeimagehosting.net/uploads/9366c1f262.jpg"]here[/url] for a screenshot of what I see. It suggests to me that the problem is within your development environment. Can anyone else please confirm that this problem is occurring with them?
#10

[eluser]hashintosh[/eluser]
[quote author="TheFuzzy0ne" date="1234550125"]No, I don't see it. Please see [url="http://www.freeimagehosting.net/uploads/9366c1f262.jpg"]here[/url] for a screenshot of what I see. It suggests to me that the problem is within your development environment. Can anyone else please confirm that this problem is occurring with them?[/quote]

It's very strange... I can see it both from my computer and from other computers, with different versions of IE...

Which address do you see in the address bar when you are on that page?
http://apache.360solutions.it/js/client/...zienda.php
or
http://apache.360solutions.it/js/client/...zienda.php

If you see the first address, it's normal that you don't have encoding problems, if you see the second you should see the small squares I was talking about.

To go to that page and see the second address, you have to use the menu and don't refresh the page, otherwise it will be redirected to the first address.

Understand what I mean?




Theme © iAndrew 2016 - Forum software by © MyBB