2015-04-04 44 views
1

我有一个使用framework7构建的phonegap应用程序,该应用程序具有'pull to refresh'选项。刷新div中的数据

这是激活拉refesh功能:

 // Pull to refresh content 
     var ptrContent = $$('.pull-to-refresh-content'); 

     // Add 'refresh' listener on it 
     ptrContent.on('refresh', function (e) { 
      // Emulate 2s loading 
      setTimeout(function() { 

       $(".content-block").empty(); 

       // Refresh the data from url 
       // reload the .content-block div 

myApp.pullToRefreshDone(); 
      }, 1000); 
     }); 

我所需要的。内容块分度,从这个url其清空后,新的数据重新加载。

不确定该怎么做 - 上面的函数工作,因为.content-block在pull之后清空。

回答

1

你必须做一个AJAX调用,然后使用它的输出,在这种情况下,插入到.content-block中。

你可以阅读更多关于AJAX在这里:

http://api.jquery.com/jquery.ajax/

下面是一些示例代码:

$.ajax({ 
    method: "GET", 
    url: "http://..." 
}).done(function(data) { 
    // The 'data' variable will contain the json data returned, which you may loop with a foreach loop and convert it into html blocks 
    var contentBlock = ""; // This variable will contain your html 
    $(".content-block").html(contentBlock); 
});