[Zope3-Users] z3c.jsonrpc response content type bug

Yuan HOng hongyuan1306 at gmail.com
Wed Oct 29 05:09:58 EDT 2008

Hi, Roger,

> That's very interesting, which JS library are you using for JSON-RPC calls
> from ExtJS?
> Or does ExtJS provide JSON-RPC calls out of the box?

No, it is regretful that ExtJS (at least 2.0.1 which I am using)
doesn't function well with z3c.jsonrpc out of the box, because
z3c.jsonrpc is expecting a content type 'application/json' while the
default json implementation of that of ExtJS sends out

So I use a slightly customized version which overrides several
functions of the default Ext.lib.Ajax, especially the request method,
to add the required header.

 Ext.lib.Ajax.asyncRequest = function(method, uri, callback, postData, async){
    var o = this.getConnectionObject();
    if (!o) {
        return null;
    else {
        o.conn.open(method, uri, async);
        if (this.useDefaultXhrHeader) {
            if (!this.defaultHeaders['X-Requested-With']) {
this.defaultXhrHeader, true);
        if(postData && this.useDefaultHeader &&
            this.initHeader('Content-Type', this.defaultPostHeader);
         if (this.hasDefaultHeaders || this.hasHeaders) {
        this.handleReadyState(o, callback);
        o.conn.send(postData || null);
        return o;

 Ext.lib.Ajax.request = function(method, uri, cb, data, options) {
        var hs = options.headers;
            for(var h in hs){
                    this.initHeader(h, hs[h], false);
            this.initHeader('Content-Type', 'text/xml', false);
            method = 'POST';
            data = options.xmlData;
        }else if(options.jsonData){
            this.headers['Content-Type'] = 'application/json';
            this.hasHeaders = true;
            method = 'POST';
            data = typeof options.jsonData == 'object' ?
Ext.encode(options.jsonData) : options.jsonData;
    var async = (options.async === false) ? false : true;
    return this.asyncRequest(method, uri, cb, data, async);

I made a report of this to the ExtJS folks. And the source code of the
most recent version 2.2 now has 'application/json' in the request
method. I suppose it should be working out of box now, although I am
still using the old version.

Hong Yuan


More information about the Zope3-users mailing list