PDA

View Full Version : Apply decodeURIComponent() for every AJAX response



cwtuan
29 Nov 2012, 12:08 PM
Hi,
For some reason, we have to encode Chinese characters in unicode at server side.
But when loading a grid, I have to decode all of them again. An Example is shown below.


columns : [ {
dataIndex : 'name',
renderer : function(value) {
return decodeURIComponent(value);
}
},{
dataIndex : 'address',
renderer : function(value) {
return decodeURIComponent(value);
}
}
]


Is it possible to apply decodeURIComponent() for every AJAX response by default so that I don't have to write decodeURIComponent() for every grid column?

Many thanks!
Tony

vietits
29 Nov 2012, 4:06 PM
Try to apply decoding at model definition by using field convert().

cwtuan
29 Nov 2012, 7:42 PM
Try to apply decoding at model definition by using field convert().
Hi, vietits
Thanks for your reply!
This method still needs to implement a converter for each model field.
It would be better if we can apply decodeURIComponent() for all Ext.Ajax's response so that we don't have to do the dirty job.
Thanks!

vietits
30 Nov 2012, 12:22 AM
If so, you can listen for 'requestcomplete' event from Ext.Ajax:


Ext.Ajax.on('requestcomplete', function(connection, response, options){
// your code here
});