【问题标题】:Retrieving Wordpress posts using a Native PhoneGap App使用本机 PhoneGap 应用程序检索 Wordpress 帖子
【发布时间】:2020-08-30 19:18:42
【问题描述】:

我是 jQuery 编程的新手,我有一个简单的应用程序,可以从 word press 网站检索帖子并将其显示在使用 Adob​​e PhoneGap Build 构建的本机应用程序中。我正在使用 Brackets 对应用程序进行编码,并且在 Brackets 模拟器上,帖子显示得很好,但问题是当我使用 PhoneGap 构建将其转换为本机应用程序时,提要不显示。这是正在进行的 Ajax 调用。

<script>

function getVideos() {

    $.support.cors=true;
    $.ajax({
        url: 'http://kukonje.com/SDC/api/get_posts/',
        dataType: 'jsonp',
        jsonp:  'callback',
        jsonpCallback: 'jsonCallback',
    }).done(function (data){
        
        data.posts.forEach(function (item) {
               
          var newsfeed = '';
          //newsfeed.append('<li><a href="#container" id="VideoFeeds" data-key="'+ item.id + '"></li>');
                 newsfeed += '<div data-role="collapsible" data-theme="b">';
            newsfeed += '<h3 <a href="#" onclick="place('+item.custom_fields.tender_latitude +','+ item.custom_fields.tender_longitude +');">'+ item.custom_fields.tender_no +' '+item.title +'</a> </h3>';
            
       
            newsfeed +='<p>' + item.date+ '</p>';
            newsfeed +='<p style="font-size:10pt;">' + '  ' +item.content + '</p>';
            newsfeed +='<p style="font-size:8pt;">P' + item.custom_fields.tender_price + '</p>';
            newsfeed +='<a href="#Purchase" class="ui-btn ui-corner-all" style="border:solid 1px red">Purchase</a>';
            newsfeed +='</div>';
            
            $('#listoffeeds').append(newsfeed);
            $('#listoffeeds').collapsibleset('refresh');
               
        });
        
    }).fail(function(error){
        alert("error - " + JSON.stringify(error));
    });
}
</script>

我不知道我应该使用 json 还是 jsonp 来检索帖子。如何确保在我使用 phonegap 构建后显示提要/帖子?

提前致谢

【问题讨论】:

  • 我不想问...您是否在本机应用程序中包含必要的依赖项? (即 jQuery、collabsibleset 等)
  • hie rnevius,是的,我正在格式化结果并在 Div 中显示它们,如下所示:
    。这显示得很好,但是当我使用电话间隙构建时,帖子不显示。
  • 我想使用相同的格式,但允许它从 word press 检索帖子并将它们读入移动设备应用程序
  • 我成功了
  • ...怎么样?请添加您的解决方案作为答案,以便其他人将来受益。

标签: android jquery ajax wordpress


【解决方案1】:

function loadtenders() {
  $.ajax({
    type: "GET",
    contentType: "application/javascript",
    url: "http://kukonje.com/?json=get_posts",
    dataType: "jsonp",
    success: function(data) {
      console.log("response = " + JSON.stringify(data) + " \n\nlength - " + data.posts.length);
      data.posts.forEach(function(item) {
        var newsfeed = '';
        newsfeed += '<div data-role="collapsible" data-theme="b">';
        newsfeed += '<h6 style="font-style:italic,font-size:8pt;"  <a href="#" onclick="place(' + item.custom_fields.tender_latitude + ',' + item.custom_fields.tender_longitude + ');"></a> <p>Tendor No: &nbsp<b>' + item.custom_fields.tender_no + ' </b></p> <p><b> ' + item.title + '</b></p></h6>';
        newsfeed += '<p> Published Date:  &nbsp' + item.date + '</p>';
        newsfeed += '<p style="font-size:10pt;">' + '  ' + item.content + '</p>';
        newsfeed += '<p style="font-size:8pt;">P' + item.custom_fields.tender_price + '</p>';
        newsfeed += '<a href="#Purchase" class="ui-btn ui-corner-all" style="background-color:#C80000 ; width: 10em;  height: 2em;">Purchase</a>';
        newsfeed += '</div>';

        $('#listoffeeds').append(newsfeed);
        $('#listoffeeds').collapsibleset('refresh');
        console.log(" Tenders loaded");

      });
    },
    error: function(data) {
      console.log("error: " + JSON.stringify(data));
    }
  });
}






$(function() {
  $("#listoffeeds").collapsibleset({
    heightStyle: "content"

  });

  $("#listoffeeds").collapsibleset({
    collapsible: true

  });

  $(window).load(function() {
    loadtenders();
  });
});
&lt;div data-role="collapsible-set" style="font-size:8pt;" data-inset="false" id="listoffeeds" data-theme="b"&gt;&lt;/div&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多