Results 1 to 3 of 3

Thread: Model class generates uneccessary Ajax request

  1. #1
    Sencha User
    Join Date
    Sep 2015
    Posts
    10

    Default Answered: Model class generates uneccessary Ajax request

    I have this simple model class :
    Code:
    Ext.define("ABC.model.andoc.AItem", {
    
        extend: "ABC.model.Base",
    
        idProperty: "itemIdentifier",
    
        fields: [
            {name: "text", type: "string"},
            {name: "cls", type: "string"},
            {name: "itemNo", type: "string"},
            {name: "mainText", type: "string"},
            {name: "action", type: "string"},
            {name: "references"},
            {name: "itemIdentifier", type: "string"}
        ]
    });
    And the base class looks like this :

    Code:
    Ext.define("ABC.model.Base", {
    
        extend: "Ext.data.Model"
    
    });
    Now this model is refered to in a tab of a tab container (its associated to a window form whose parent is the tab). Now when I switch to this tab for the first time, I see this strange request in the logs :

    Code:
    http://localhost:1841/ABC.model.andoc.AItem?_dc=1442254857389&node=root
    The above is a URL that does not exist, since I have the model under a folder structure - model/andoc/AItem.js


    The response text is "Not Found" and I see the following also in the logs
    Code:
    JSON.decode(): You're trying to decode an invalid JSON String: Not Found
    What am I doing wrong ?

  2. Hi,

    It appears (from the request) that this is a model for a tree store. From the looks of it, you have your root specify with expanded: true so an initial request will be made for the root content. As you have no proxy and URL defined on the model (and it would appear nor on the tree store) the framework will attempt to derive a URL based on the model name itself.

    In order to correctly retrieve your content, please specify a proxy on the treestore or model so that the data can be obtained from the correct url - in this case something like this :

    Code:
    proxy: {
        type: 'ajax',
        url: 'model/andoc/AItem.js',
        reader: {
             type: 'json'
        }
    }
    Please note that if indeed your data is stored in a .js file as a JSON object you may wish to rename that source to .json as, depending upon
    your server configuration, .js files will be transferred with content type application/javascript rather than application/json

    Regards,

    Kevin
    Sencha Support Team

  3. #2
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    388
    Answers
    13

    Default

    Hi,

    It appears (from the request) that this is a model for a tree store. From the looks of it, you have your root specify with expanded: true so an initial request will be made for the root content. As you have no proxy and URL defined on the model (and it would appear nor on the tree store) the framework will attempt to derive a URL based on the model name itself.

    In order to correctly retrieve your content, please specify a proxy on the treestore or model so that the data can be obtained from the correct url - in this case something like this :

    Code:
    proxy: {
        type: 'ajax',
        url: 'model/andoc/AItem.js',
        reader: {
             type: 'json'
        }
    }
    Please note that if indeed your data is stored in a .js file as a JSON object you may wish to rename that source to .json as, depending upon
    your server configuration, .js files will be transferred with content type application/javascript rather than application/json

    Regards,

    Kevin
    Sencha Support Team

  4. #3
    Sencha User
    Join Date
    Sep 2015
    Posts
    10

    Default

    Thanks, indeed I am using the model with a Tree Store, however, I have my tree store defined on the view model of the main form which contains other text fields apart from the tree panel :

    Code:
    data: {    ....},
    stores: {
        treeItems: {
            type: "tree",
            model: "ABC.model.andoc.AItem",
            autoload: true,
            root: true
    }
    },

    THe treepanel is bound directly to the store on the form like this :

    Code:
    bind: "{treeItems}",
    For that reason I have set root: true. I saw "rootProperty", but couldn't figure out how to use it in this context.

    K

Similar Threads

  1. Replies: 8
    Last Post: 11 Jun 2015, 11:49 PM
  2. How to refactor Ext.Ajax.request to Ext.Model.save
    By warrean in forum Sencha Touch 2.x: Q&A
    Replies: 4
    Last Post: 7 Dec 2012, 7:46 AM
  3. Ext.Ajax.request return .net class ?
    By Rothariger in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 29 Sep 2008, 8:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •