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 8456619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:35:29+00:00 2026-06-10T12:35:29+00:00

I have the following line in my script, building a string based on news

  • 0

I have the following line in my script, building a string based on news feed data retrieved from JSON:

 var buildstring = "<table><tr><img src=" + obj.value.items[x]["media:content"].url + "> <b>" + obj.value.items[x].title + "</b><br /><td>" + obj.value.items[x].description.content + "</td></tr></table><br />";

In general it works fine – except for one thing. The feed that is being parsed occasionally doesn’t have an image file associated with a particular title and description, and in that case, the entire script fails.

Is there any way to get the script to skip over any missing item in the feed and to build the string from the items that are there? E.g. if there is no image file for a story, the string consists of just the title and description? In the typical case I am taking 5 – 10 stories – if all of them have the 3 elements (image, title and description.content), it’s all fine. If one story is missing the image file, I get nothing at all.

Thanks for any advice or assistance.

EDIT:

More complete code:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"> </script><script type="text/javascript">

function pipeCallback(obj) {
document.write("<div id=testdiv><b>LATEST NEWS</b><hr>");
var x;
for (x = 0; x < obj.count ; x++)
{
var imageurl = obj.value.items[x]["media:content"].url ? obj.value.items[x]["media:content"].url : "http://static.jquery.com/org/images/project/jquery-project-sm.png";
var buildstring = "<table><tr><img src=" + imageurl + "> <b>" + obj.value.items[x].title + "</b><br /><td>" + obj.value.items[x].description.content + "</td></tr></table><br />";
document.write(buildstring);
buildstring = null;
}
document.write("</div>");

}
</script>
  • 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-06-10T12:35:30+00:00Added an answer on June 10, 2026 at 12:35 pm

    You could use a ternary expression to build the string:

    var textOnly = "<b>" + obj.value.items[x].title + "</b><br /><td>" + obj.value.items[x].description.content + "</td></tr></table><br />";
    var buildstring = (typeof obj.value.items[x]["media:content"] == 'undefined') ? 
        "<table><tr><td><img src=" + obj.value.items[x]["media:content"].url + "></td>" + textOnly 
        : "<table<tr><td></td>" + textOnly;
    

    Obviously this gets really ugly, fast, which is why they invented client-side templating (JQuery templating, Underscore.js, Mustache.js, Handlebars.js, etc, take your pick).

    These allow you to separate the data from the markup, so you can write something like this:

    var template = "<table><tr><td><img src='{{ image }}' /></td><td>{{ title }}</td><td>{{ description }}</td></tr></table>";
    

    And you can get the HTML by from the data + template:

    var html = Mustache.render(template, obj.value.items[x]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following method having following line inside it HtmlPage.Window.Invoke(showPopUp,new string[] {Hello from Silverlight});
I have the following line in a script I am running in the Run
I have a #!/bin/sh script that has the following line: if [ ! -x
I have error at the first line of the following code while building with
I have the following line in my unix script file: if [[ -f $DIR1/$FILE1
I'm writing a script to backup a database. I have the following line: mysqldump
I have the following line of code - <a href=/wordpress/wp-content/trackclicks/clickcounter.php?var=<?php echo $var3; ?> onclick=return
I have the following script (modified to remove any private information). -- This line
I have the following line at the first line in my script file: #!/bin/sh
I'm using ASP.Net Dynamic Data. I have the following line in my site.master page.

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.