PDA

View Full Version : Ext.Ajax.request header problem



rjuncu
11 Aug 2010, 6:55 AM
Hi,

I have all my html pages using the iso-8859-1 charset, so, I have to use in my Ajax requests, this charset too.

My code looks like this :


Ext.Ajax.request({
url: '/perl/Parametrage/elementGestion_extjs.pl'
,method: 'POST'
,jsonData: {'name' : 'nimportequoi '}
,defaultHeaders: {
'Content-Type': 'application/json; charset=iso-8859-1'
}


Well, the problem is, that in firebug I found always the value 'application/json; charset=UTF-8' for the request header.
I've also tried to set headers property of Ext.Ajax.request and the defaultHeaders property for Ext.Ajax global or Ext.lib.Ajax.

I've tried too to debug to see where the header is changed, couldn't figure out either.

The real problem is that I have to post some latin characters ( ...) but I found them in the request string as 'é' 'è' or ' '

I see that Ext.encode doesn't change these values, in Firebug the postData value passed to the XmlHttpRequest object seems all right.

I use Ext 3.2

Any idea is welcome.

Animal
11 Aug 2010, 7:17 AM
http://www.w3.org/TR/XMLHttpRequest/#the-send-method

It encodes using UTF-8

Doesn't matter how the server originally encoded the characters of your HTML page.

rjuncu
11 Aug 2010, 7:17 AM
In fact, it seems that the charset problem is not due to ExtJS, I have the same problem if I create the XMLHttpRequest object myself. But I still can't see how to solve the problem.

rjuncu
11 Aug 2010, 7:17 AM
http://www.w3.org/TR/XMLHttpRequest/#the-send-method

It encodes using UTF-8

Doesn't matter how the server originally encoded the characters of your HTML page.
Right, didn't see your answer

rjuncu
11 Aug 2010, 7:49 AM
http://www.w3.org/TR/XMLHttpRequest/#the-send-method

It encodes using UTF-8

Doesn't matter how the server originally encoded the characters of your HTML page.
Well, it seems that the only solution I have is to escape all characters posted to server and unescape them there. Not quite elegant.

Animal
11 Aug 2010, 7:58 AM
Just get your server to behave itself!

The XHR will send



Content-Type: application/x-www-form-urlencoded; charset=UTF-8


So the server should know how to decode the byte stream back into characters.