【发布时间】:2020-08-30 19:18:42
【问题描述】:
我是 jQuery 编程的新手,我有一个简单的应用程序,可以从 word press 网站检索帖子并将其显示在使用 Adobe 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