2012-03-06 4 views
1

私のSenchaアプリケーションでは、ajaxリクエストの代わりにjsonpリクエストを呼び出す必要がありますが、jsonpリクエストのデモを提供してください。Sencha TouchアプリケーションでJSONPリクエストを呼び出す方法

はあなたに煎茶のドキュメントから

+0

この質問を参照 - [Sencha Touchを使用したモバイルアプリケーション - JSONリクエストで構文エラーが生成される] [1] [1]:のhttp:// stackoverflowのhttp://stackoverflow.com/questions/3881779/mobile-application-using-sencha-touch-json-request-generates-syntax-error – Anthony

+0

これをチェックしてください。 com/questions/9596166/how-to-access-jsonp-data-using-ext-util-jsonp-request – Swar

答えて

1

サンプルJSONリクエストに感謝:) ここでの詳細へのリンクです:http://docs.sencha.com/touch/2-0/#!/api/Ext.data.JsonP

Ext.data.JsonP.request({ 
     url: 'http://free.worldweatheronline.com/feed/weather.ashx', 
     callbackKey: 'callback', 
     params: { 
      key: '23f6a0ab24185952101705', 
      q: '94301', // Palo Alto 
      format: 'json', 
      num_of_days: 5 
     }, 
     success: function(result) { 
      //Your success function here... 
     } 
    }); 
1

私のために正常に動作し、以下のコードをチェック:)

  Ext.define('APP.view.List', { 
       extend: 'Ext.Container', 
       requires: [ 
        'Ext.data.JsonP' 
       ], 
       config: { 
        scrollable: true, 
        items: [{ 
          xtype: 'panel', 
          id: 'JSONP' 
         }, { 
         docked: 'top', 
         xtype: 'toolbar', 
         items: [{ 
          text: 'Load using JSON-P', 
          handler: function() { 
           var panel = Ext.getCmp('JSONP'), 
            tpl = new Ext.XTemplate([ 
            '<div class="demo-weather">', 
             '<tpl for=".">', 
              '<div class="day">', 
               '<div class="date">{date}</div>', 
               '<tpl for="weatherIconUrl">', 
                '<img src="{value}">', 
               '</tpl>', 
               '<span class="temp">{tempMaxF}°<span class="temp_low">{tempMinF}°</span></span>', 
              '</div>', 
             '</tpl>', 
            '</div>' 
           ]); 

           panel.getParent().setMasked({ 
            xtype: 'loadmask', 
            message: 'Loading...' 
           }); 

           Ext.data.JsonP.request({ 
            url: 'http://free.worldweatheronline.com/feed/weather.ashx', 
            callbackKey: 'callback', 
            params: { 
             key: '23f6a0ab24185952101705', 
             q: '94301', // Palo Alto 
             format: 'json', 
             num_of_days: 5 
            }, 

            callback: function(success, result) { 
             var weather = result.data.weather; 

             if (weather) { 
              panel.updateHtml(tpl.applyTemplate(weather)); 
             } 
             else { 
              alert('There was an error retrieving the weather.'); 
             } 

             panel.getParent().unmask(); 
            } 
           }); 
          } 
         }] 
        }] 
       } 
      }); 
関連する問題