Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:51+00:00 2026-05-23T10:53:51+00:00

UPDATE 6: Based on the console.log , I have noticed that some of the

  • 0

UPDATE 6:

Based on the console.log, I have noticed that some of the objects have:

thumbnail: Array[2]

Others have:

thumbnail: Object

and others don’t have it at all.

So it seems that what @Felix Kling could be true.

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Frss.xml%22&format=json&callback=cbfunc

if you can’t access the link, try:

http://pastebin.com/T4GPQvtk

UPDATE 5:

I am still getting url as undefined with:

for (var i = 0; i < news.length; i++) {
    news[i].thumbnail = ( $.isArray( news[i].thumbnail ) ) ? news[i].thumbnail : [news[i].thumbnail];

    buildHTML.push( "<a href='" + news[i].thumbnail[0].url + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );
}

UPDATE 4:

The following:

buildHTML.push( "<a href='" + news[i].thumbnail[0] ? news[i].thumbnail[0].url : $.isArray( news[i].thumbnail ) + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );

gives me:

Uncaught TypeError: Cannot read property 'url' of undefined

UPDATE 3:

The following does not seem to work either:

buildHTML.push( "<a href='" + news[i].thumbnail[0] ? news[i].thumbnail[0].url : news[i].thumbnail.url + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );

The error I get is:

Uncaught TypeError: Cannot read property 'url' of undefined

UPDATE 2:

The following does not seem to work:

buildHTML.push( "<a href='" + news[i].thumbnail=$.isArray(news[i].thumbnail)?news[i].thumbnail:[news[i].thumbnail] + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );

The error I get is:

Uncaught ReferenceError: Invalid left-hand side in assignment
$.ajax.successyql_news_widget.js:25
bjquery-1.4.2.min.js:124
c.extend.ajax.Ajquery-1.4.2.min.js:125
(anonymous function)yql:1

UPDATE 1:

The problem happens, when I add the image to push as follows:

buildHTML.push( "<img src='" + news[i].thumbnail[0].url + "' /><a href='" + news[i].link + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );

ORIGINAL QUESTION:

From the following url:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Frss.xml%22&format=json&callback=cbfunc

I am trying to capture the data via a look like this:

function get_news() {
    $.ajax({
        url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Frss.xml%22&format=json&callback=cbfunc&rand=" + Math.random(),
        type: 'GET',
        dataType: 'jsonp',
        jsonp: 'callback',
        jsonpCallback: 'cbfunc',
        error: function(xhr, status, error) {
            alert(xhr.responseText);
        },
        success: function(data) { 

            var buildHTML = [];

            var news = data.query.results.rss.channel.item;

            for (var i = 0; i < news.length; i++) {
                buildHTML.push( "<a href='" + news[i].link + "' target='_blank'>" + news[i].title + "</a><br />" + news[i].pubDate );
            }

            $('.portlet-content').empty().append(buildHTML.join("<br /><br />"))

        }

    });

}

This works fine as long as the thumbnail section looks like this:

"thumbnail": [
{
    "height": "49",
    "url": "http://news.bbcimg.co.uk/media/images/48915000/jpg/_48915868_48915872.jpg",
    "width": "66"
}
{
    "height": "81",
    "url": "http://news.bbcimg.co.uk/media/images/52468000/jpg/_52468689_48915872.jpg",
    "width": "144"
}
]

However, when the thumbnail section looks like this:

"thumbnail": {
    "height": "81",
    "url": "http://news.bbcimg.co.uk/media/images/53705000/jpg/_53705922_012314461-1.jpg",
    "width": "144"
}

I get an error “undefined”, the loop stops and I get nothing on the screen.

How do I ignore those, and continue the script without it stopping on the error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:53:52+00:00Added an answer on May 23, 2026 at 10:53 am

    Based on your comments, you seem to want this:

    for (var i = 0; i < news.length; i++) {
        var item = news[i];
    
        if($.isArray(item.thumbnail)) {
            var size = +item.thumbnail[0].width * +item.thumbnail[0].height,
                selected = 0;
            for(var j = 1, jl = item.thumbnail.length; j < jl; j++) {
                var t_size = +item.thumbnail[j].width * +item.thumbnail[j].height;
                if(t_size < size) {
                    size = t_size;
                    selected = j;
                }
            }
            buildHMTL.push("<img src='" + news[i].thumbnail[selected].url + "' />");
        }
        buildHTML.push( "<a href='" + item.link + "' target='_blank'>" + item.title + "</a><br />" + item.pubDate );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a case where I need to update a jqgrid based on some
I have a container object that contains of set of objects that is persisted
Update: Based on a couple of the answers I have received, I just want
UPDATE: Based on rrenaud's great comment I wanted to clarify that although I'm generating
I have a fairly simple console app that monitors an exchange mailbox, picks particular
based on the docs for knockout.mapping.js it says that properties of a data object
I have a toolbar that exists on all my webpages that makes requests to
I have the following submit handler which should lookup for some value based on
I have some trivial code that looks like this: SortedDictionary<String, long> d = new
I have a database table that contains some records to be processed. The table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.