1. #1
    Ext User
    Join Date
    Jul 2009
    Posts
    15
    Vote Rating
    0
    Denis49 is on a distinguished road

      0  

    Default Error with JSONStore

    Error with JSONStore


    Hi,
    I have an issue with ExtJS 3.0 RC2 with JSONStore:

    Here is my store:

    Code:
    list_store[y] = new Ext.data.JsonStore({
            storeId:nomS,
            url:function(){
                if(y=='rien'){
                    var mon_url = 'requete3.php?id=' + pageVal+url_R[ongl_select];
                }
                else{
                    var mon_url = 'requete3.php?id=' + pageVal+url_R[y];
                }
                return mon_url;
            },
            totalProperty: 'total',
            root: 'dataF',
            totalProperty: 'totalCount',
            success: function(){
                alert('ok');
            },
            failure:function(){
                alert('bug');
            },
            fields: eval(tab_cols),
            listeners:{
                load:function(store){
                    var tmp = 'total'+y;
                    if (window.XMLHttpRequest){
                          var page_connect = new XMLHttpRequest();
                    }
                    else {
                        if (window.ActiveXObject){
                          var page_connect=requete_ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
                        }
                    }
                    page_connect.open ('GET', 'numero_page.php?ecran='+y, false);
                    page_connect.send(null);
                    var data_page = eval('('+page_connect.responseText+')');
                    var aff_page = data_page.page+'/'+data_page.nb;
                    Ext.getCmp(tmp).setText('Total : '+store.getTotalCount()+'  -   Page '+aff_page);
                }
            }
        });
    and when I call load() with:

    Code:
    list_store[y].load();
    an exception is raised:

    Code:
    [Exception... "'Ext.data.Api: Invalid url. Please review your proxy configuration.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
    I state that it works with ExtJS 2.2.

    If someone knows... thanks in advance.

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    According to the docs, the URL must be a string.

    It's only Ext.data.Connection that offers the ability to use a function.

    Anyway, you are not using different URLs.

    You are sending different parameters.

    So what you need is a beforeload listener.

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    And what's this horror?

    Code:
                    if (window.XMLHttpRequest){
                          var page_connect = new XMLHttpRequest();
                    }
                    else {
                        if (window.ActiveXObject){
                          var page_connect=requete_ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
                        }
                    }
                    page_connect.open ('GET', 'numero_page.php?ecran='+y, false);
                    page_connect.send(null);
                    var data_page = eval('('+page_connect.responseText+')');
                    var aff_page = data_page.page+'/'+data_page.nb;
                    Ext.getCmp(tmp).setText('Total : '+store.getTotalCount()+' &nbsp;-&nbsp;  Page '+aff_page);

  4. #4
    Ext User
    Join Date
    Jul 2009
    Posts
    15
    Vote Rating
    0
    Denis49 is on a distinguished road

      0  

    Default


    Thanks for this fast answer!
    I made it working by creating my url before, and just passing the string in the store.
    But I still don't understand why it worked with ext 2.2 and not with 3.0... in the docs, nothing has changed apparently, so could you enlight me?

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    The way it creates URLs has changed.

    You could try this override:

    Code:
    Ext.override(Ext.data.DataProxy, {
        buildUrl : function(action, record) {
            record = record || null;
            var url = (this.api[action]) ? this.api[action].url : Ext.isFunction(this.url) ? this.url() : this.url;
            if (!url) {
                throw new Ext.data.Api.Error('invalid-url', action);
            }
    
            var format = null;
            var m = url.match(/(.*)(\.\w+)$/);  // <-- look for urls with "provides" suffix, eg: /users.json, /users.xml, etc
            if (m) {
                format = m[2];
                url = m[1];
            }
            // prettyUrls is deprectated in favor of restful-config
            if ((this.prettyUrls === true || this.restful === true) && record instanceof Ext.data.Record && !record.phantom) {
                url += '/' + record.id;
            }
            if (format) {   // <-- append the request format if exists (ie: /users/update/69[.json])
                url += format;
            }
            return url;
        }
    });

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    If that works, try submitting it as a bug report.

  7. #7
    Ext User
    Join Date
    Jul 2009
    Posts
    15
    Vote Rating
    0
    Denis49 is on a distinguished road

      0  

    Default


    No, it doesn't work, url is still undefined.

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Ah well, you could debug it then.

  9. #9
    Ext User
    Join Date
    Jul 2009
    Posts
    15
    Vote Rating
    0
    Denis49 is on a distinguished road

      0  

    Default


    ok, the beforeload listener (thanks Animal) works for changing dynamically the url:

    Code:
    beforeload: function(){
                    if(y=='rien'){
                        this.proxy.setUrl(url_R[ongl_select] + pageVal, false);
                    }
                    else{
                        this.proxy.setUrl(url_R[y] + pageVal, false);
                    }
                },

Thread Participants: 1