来自url的Img src没有加载到phonegap android中

时间:2013-07-17 05:34:06

标签: javascript android html5 cordova

我正在创建一个加载json数据的应用程序,其中包含图片网址和一些数据。我在deviceready上调用了该服务。 我得到成功的回复,我动态加载div的内容取决于响应。

  

当我尝试通过将url分配给src来从url加载图像时   img它有时不会加载所有图像。但它完美无缺   windows phone。

CODE:

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();
            }
        }

    });

}

0 个答案:

没有答案