bontade
bontade

Reputation: 3224

ExtJs loading data

I'm trying to load data from imdb, but i have no results in table (GridPanel). It's my source code:

...
<body>
<script type="text/javascript">
 Ext.onReady(function(){

var store1 = new Ext.data.JsonStore({
    root: 'root',
    idProperty: 'ID',
    remoteSort: true,
    fields: [
        'Title'
    ],
    // load using script tags for cross domain, if the data in on the same domain as
    // this page, an HttpProxy would be better
    proxy: new Ext.data.ScriptTagProxy({
        url: 'http://www.imdbapi.com/?t=True%20Grit'
    })
});
 // building grid panel
});
</script>
<div id="topic-grid"></div>
...

Maybe should I change 'root' parameter in JsonStore?


UPDATE

I tried to use HttpProxy, but still no results. I put my all body contents maybe it will be more helpful.

<script type="text/javascript">
Ext.onReady(function(){

var store1 = new Ext.data.JsonStore({

    reader: new Ext.data.JsonReader({
        fields: ['Title'],
        root: 'rows'
        }),

    // load using script tags for cross domain, if the data in on the same domain as
    // this page, an HttpProxy would be better
    proxy: new Ext.data.HttpProxy({
        url: 'http://www.imdbapi.com/?t=True%20Grit'
    }),
    autoLoad: true
  });

var grid1 = new Ext.grid.GridPanel({
    width:700,
    height:500,
    title:'ExtJS.com - Browse Forums',
    store: store1,
    trackMouseOver:false,
    disableSelection:true,
    loadMask: true,

    // grid columns
    columns:[{
        id: 'Title', 
        header: "Topic",
        dataIndex: 'Title',
        width: 420,
        sortable: true
    }]
});


// render it
grid1.render('topic-grid');

// trigger the data store load
store1.load({params:{start:0, limit:25}});
});
</script>
<div id="topic-grid"></div>

Upvotes: 1

Views: 1409

Answers (1)

Ryan
Ryan

Reputation: 1557

You can't get a JSON directly from the response when using a ScriptTagProxy. You can only get executable javascript, and unfortunately, the imdbapi site doesn't return executable javascript. Also, you can't use HttpProxy to do cross-site scripting (XSS). You can only make connections to resources (e.g., files) on your own local domain.

One possibility for you:

  1. Set up a server-side file on your own domain that your proxy will connect to.
  2. Instead of a ScriptTagProxy, use an HttpProxy that contacts your server-side file.

    proxy: new Ext.data.HttpProxy({
        url: '/path/to/my/server/file?t=True%20Grit'  // the leading slash in 
                                                      // this url will begin from
                                                      // your web server's root
                                                      // directory for your
                                                      // web-accessible files
    })
    
  3. Have your server-side file make the imdb api call on behalf of the client and output the results of the imdb api as a JSON back to the client.

    myServerSideFile
    ================
    
    // harvest GET parameters, e.g., in your case, the query param 't' with value
    // True%20Grit
    
    // use the GET parameters to form a url with the GET params on the end, e.g.,
    // in your case, http://www.imdbapi.com/?t=True%20Grit
    
    // call the imdb api using this url
    
    // return the imdb api results as a JSON
    

See this for more details and examples of doing the above suggestion in various server-side technologies.

Upvotes: 3

Related Questions