2012-03-06 81 views
1

在我的sencha应用程序中,我需要调用jsonp请求而不是ajax请求,但是我不知道如何编写它。所以请为我提供演示jsonp请求。如何在Sencha Touch应用程序中调用JSONP请求

感谢您从煎茶文档

+0

请参阅此问题 - [使用Sencha Touch的移动应用程序 - JSON请求生成语法错误] [1] [1]:http://stackoverflow.com/questions/3881779/mobile-application-using-sencha-touch-json-request-generates-syntax-error – Anthony 2012-03-07 05:55:41

+0

选中此项:http:// stackoverflow。 COM /问题/ 9596166 /如何对访问JSONP数据,使用-EXT-UTIL-JSONP请求 – Swar 2012-03-07 08:08:20

回答

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(); 
            } 
           }); 
          } 
         }] 
        }] 
       } 
      }); 
相关问题