我正在创建一个加载具有图像 url 和一些数据的 json 数据的应用程序。我在 deviceready 上调用了该服务。我得到了成功的响应,我根据响应动态加载 div 的内容。
当我尝试通过将 url 分配给 img 中的 src 来从 url 加载图像时,它有时不会加载所有图像。但它在 Windows Phone 上运行完美。
代码:
function Local(action, i)
{
navigator.notification.activityStart("Please Wait...", "Loading");
$.ajax(
{
url: 'myurl',
type: 'get',
dataType: 'json',
error: function (error)
{
navigator.notification.alert(
'Unable to reach server..', // message
alertDismissed(), // callback to invoke with index of button pressed
'', // title
'OK' // buttonLabels
);
},
success: function (data)
{
try
{
var newslist = data.NewsList;
try
{
var news = newslist.News;
var Value = "";
for (var i = 0; i < news.length; i++)
{
var head = news[i].headline;
var abstract = news[i].abstract;
if (head.length > 30)
head = head.substr(0, 30) + "...";;
if (abstract.length > 80)
abstract = abstract.substr(0, 80) + "...";;
Value += "<div style='height:20%; float:left; width:100%; background:#ffffff; padding:2%; border-bottom: 2% solid #fff;'>" +
"<a href='article.html' id='" + news[i].articleid + "' style='height:95%; align:center; float:left; width:100%;' onClick='reply_click(this.id)'>" +
"<div style='height: 100%; text-align:center; float:left; width:30%;'>" +
"<div style='height:5%; width:30%; text-align:center;'></div>" +
"<img src='" + news[i].Articleid + "' style=' background-color:#ffffff; width:auto; height:100%;'/>" +
"<div style='height:5%; width:30%; text-align:center;'></div>" +
"</div>" +
"<div style=' text-align:justify; height:100%; float:left; width:68%;'>" +
"<div style=' overflow:hidden; height:20%; float:left; width:100%;'>" +
"<span style=' color:#da1e15; align:justify;'>" + head + "</span>" +
"</div>" +
"<div style='float:left; overflow:hidden; height:80%; width:100%;'>" +
"<span style='color:#000000;'>" + abstract + "</span>" +
"<div style='height:5%;'></div>" +
"</div>" +
"</div>" +
"</a>" +
"<div style='height:5%; float:left; width:100%;'><hr></div>" +
"</div>";
}
scroller2.insertAdjacentHTML("beforeEnd", "<div style='height:5%; float:left; width:100%;'></div>");
scroller2.insertAdjacentHTML("beforeEnd", Value);
navigator.notification.activityStop();
}
catch (err)
{
navigator.notification.alert(
'No data available in this Category..', // message
alertDismissed(), // callback to invoke with index of button pressed
'No data', // title
'OK' // buttonLabels
);
navigator.notification.activityStop();
}
}
catch (err)
{
navigator.notification.alert(
'Try Again Later...', // message
alertDismissed(), // callback to invoke with index of button pressed
'Error', // title
'OK' // buttonLabels
);
navigator.notification.activityStop();
}
}
});
}