我是jquery编程的新手,我有一个简单的应用程序,可以从word新闻网站检索帖子并将其显示在使用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构建后,如何确保Feed /帖子显示。
提前完成 `
答案 0 :(得分:0)
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:  <b>' + item.custom_fields.tender_no + ' </b></p> <p><b> ' + item.title + '</b></p></h6>';
newsfeed += '<p> Published Date:  ' + 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();
});
});
<div data-role="collapsible-set" style="font-size:8pt;" data-inset="false" id="listoffeeds" data-theme="b"></div>