1. #1
    Sencha User
    Join Date
    Oct 2013
    Posts
    3
    Vote Rating
    1
    VatsanMadabushi is on a distinguished road

      0  

    Default Answered: How to load XML data into a Grid coming from a service - HELP HELP!!!!!!!

    Answered: How to load XML data into a Grid coming from a service - HELP HELP!!!!!!!


    I am very new to ExtJs and trying to learn it.

    I have created a MVC (as below). I see the xml retuned from the PHP service, but it doesnt populate into the grid. I have seen examples where a static xml file is used but not where a ajax call returns a xml string. All the code that is below is based on teh Grid Component example.
    In this case, I see the grid rendered but it has no data. So I am not sure if my store is incorrect or grid is not getting updated.
    Each of the below are in individual js file.

    XML from php script:

    <?xml version='1.0' encoding='UTF-8'?>
    <ErrorList success='true'>
    <error>
    <message>OPEN</message>
    <count>10</count>
    </error>
    <error>
    <message>CLOSED</message>
    <count>10</count>
    </error>

    </ErrorList >


    App:
    Ext.application({

    requires: ['Ext.container.Viewport'],
    name: 'EG',

    appFolder: 'app',
    controllers: [
    'GridController'
    ],

    launch: function() {
    Ext.create('Ext.container.Viewport', {
    layout: 'fit',
    items: [
    {
    xtype: 'errorlist',
    title: 'Errors',
    html : 'List of errors will go here'
    }
    ]
    });
    }
    });
    ;


    Model:
    Ext.define('EG.model.ErrorDetail', {
    extend: 'Ext.data.Model',
    fields: [{name:'message', mapping: 'message'},
    {name: 'count', mapping: 'count'}
    ]
    });

    Store:
    Ext.define('EG.store.Errors', {
    extend: 'Ext.data.Store',
    model: 'EG.model.ErrorDetail',
    storeId: 'ErrorResponseStore',
    requires: [
    'EG.model.ErrorDetail'
    ],

    autoLoad: 'true',
    autoSync: 'true',
    proxy: {
    type: 'ajax',
    url: 'http://136.151.194.44:8080/jpDemo/ErrorList.php',
    autoLoad: 'true',
    autoSync: 'true',
    reader: {
    type: 'xml',

    //model: 'ErrorDetail',
    root: 'ErrorList',
    record: 'error'
    //idProperty: 'message',
    //successProperty: '@success'
    }
    }

    });

    View:
    Ext.define('EG.view.performance.Perform' ,{
    extend: 'Ext.grid.Panel',
    alias: 'widget.errorlist',

    title: 'All Errors',
    store: 'Errors',
    columns: [
    {text: "Error", flex: 1, dataIndex: 'message'},
    {text: "Count", dataIndex: 'count'}
    ],
    renderTo:Ext.getBody()

    });

    Controller:
    Ext.define('EG.controller.GridController', {
    extend: 'Ext.app.Controller',
    stores: ['Errors'],
    models: ['ErrorDetail'],

    views: [
    'performance.Perform'
    ],

    init: function() {
    this.control({
    'viewport > panel': {
    render: this.onPanelRendered
    },
    'errorlist': {
    itemdblclick: this.editUser
    }

    });
    },

    editUser: function(grid, record) {
    console.log('Double clicked on ' + record.get('name'));
    },

    onPanelRendered: function() {
    console.log('The panel was rendered');
    }

    });

  2. Both the browser and the "server" are running on the same PC s CORS is not an issue.
    It's a little odd to specify the full URL on the proxy if it has the same origin as the page.

    Also, each on the MVC classes are in separate js files. Is Ext direct the only way for this? If so, then what about cases where this is a true WS and not a php script?
    I don't understand what you mean by this. Ext Direct is certainly not the only way to do anything.

    I am able to see the xml response using Firebug but the header content type is "text/html" even though that I set it to "text/xml" in the php script.
    You need to get the response content-type header correct or it won't work.

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,508
    Answers
    528
    Vote Rating
    288
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Does the URL for your AJAX request have the same origin as your page? If not, are you expecting it to load via CORS and do you have suitable headers for that to work?

    If the origin isn't the problem then it may be the content-type header on your response.

  4. #3
    Sencha User
    Join Date
    Oct 2013
    Posts
    3
    Vote Rating
    1
    VatsanMadabushi is on a distinguished road

      0  

    Default


    PM
    skirtle,
    Both the browser and the "server" are running on the same PC s CORS is not an issue. Also, each on the MVC classes are in separate js files. Is Ext direct the only way for this? If so, then what about cases where this is a true WS and not a php script?
    I am able to see the xml response using Firebug but the header content type is "text/html" even though that I set it to "text/xml" in the php script.

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,508
    Answers
    528
    Vote Rating
    288
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      1  

    Default


    Both the browser and the "server" are running on the same PC s CORS is not an issue.
    It's a little odd to specify the full URL on the proxy if it has the same origin as the page.

    Also, each on the MVC classes are in separate js files. Is Ext direct the only way for this? If so, then what about cases where this is a true WS and not a php script?
    I don't understand what you mean by this. Ext Direct is certainly not the only way to do anything.

    I am able to see the xml response using Firebug but the header content type is "text/html" even though that I set it to "text/xml" in the php script.
    You need to get the response content-type header correct or it won't work.

  6. #5
    Sencha User
    Join Date
    Oct 2013
    Posts
    3
    Vote Rating
    1
    VatsanMadabushi is on a distinguished road

      1  

    Default resolved

    resolved


    skirtle,
    that was the issue. Once I fixed the php script to return the correct content type, I see the dta populated now.

Thread Participants: 1

Tags for this Thread