1

imdb からデータを読み込もうとしていますが、テーブル (GridPanel) に結果がありません。それは私のソースコードです:

...
<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>
...

JsonStore の「root」パラメータを変更する必要がありますか?


アップデート

HttpProxy を使用しようとしましたが、まだ結果がありません。私は私のすべての体の内容を入れました。

<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>
4

1 に答える 1

3

ScriptTagProxy を使用する場合、応答から直接 JSON を取得することはできません。実行可能な JavaScript しか取得できません。残念ながら、imdbapi サイトは実行可能な JavaScript を返しません。また、HttpProxy を使用してクロスサイト スクリプティング (XSS) を実行することはできません。自分のローカル ドメイン上のリソース (ファイルなど) への接続のみを行うことができます。

あなたのための1つの可能性:

  1. プロキシが接続する独自のドメインにサーバー側ファイルを設定します。
  2. ScriptTagProxy の代わりに、サーバー側のファイルに接続する HttpProxy を使用します。

    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. サーバー側ファイルでクライアントに代わって imdb API 呼び出しを行い、imdb API の結果を JSON としてクライアントに出力します。

    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
    

さまざまなサーバー側テクノロジーで上記の提案を実行する詳細と例については、これを参照してください。

于 2011-10-29T05:42:22.270 に答える