View Full Version : ScriptTagProxy charset problem

22 Jul 2010, 1:41 AM
We had some problem using ScriptTagProxy because of the character encoding (UTF-8) of our application.
We needed to write a patch on the class ScriptTagProxy to set the charset attribute on the generated script tag.

This is because Internet Explorer ignores the encoding of the sent script. It just uses the charset of the hosting html page if the charset attribute of the script tag is not set.

In our case, the page including the script use the charset ISO-8859-1, but the application (other domain) that send data by the tag proxy use a UTF-8 encoding. This causes problems with special character if the charset of the script tag is not set.

It would be nice to make the charset attribute as param. If a null value is passed than any charset attribute is set and the script use that one of the page.

Our patch with fixed charset is below

Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, {
timeout : 30000,
callbackParam : "callback",
nocache : true,

doRequest : function(action, rs, params, reader, callback, scope, arg) {
var p = Ext.urlEncode(Ext.apply(params, this.extraParams));
var url = this.buildUrl(action, rs);
if (!url) {
throw new Ext.data.Api.Error('invalid-url', url);

url = Ext.urlAppend(url, p);

url = Ext.urlAppend(url, '_dc=' + (new Date().getTime()));

var transId = ++Ext.data.ScriptTagProxy.TRANS_ID;

var trans = {
id : transId,
action: action,
cb : "stcCallback"+transId,
scriptId : "stcScript"+transId,
params : params,
arg : arg,
url : url,
callback : callback,
scope : scope,
reader : reader

window[trans.cb] = this.createCallback(action, rs, trans);

url += String.format("&{0}={1}", this.callbackParam, trans.cb);

if(this.autoAbort !== false){

trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
var script = document.createElement("script");
script.setAttribute("src", url);
script.setAttribute("type", "text/javascript");
script.setAttribute("id", trans.scriptId);
script.setAttribute("charset", "UTF-8");

this.trans = trans;


22 Jul 2010, 2:48 AM
It should be a config option.

22 Jul 2010, 4:53 AM
It should be a config option.

This config option already exists?
I do not see it in http://www.sencha.com/deploy/dev/docs/?class=Ext.data.ScriptTagProxy