0

My feed does not pull data

I am a newbie to YQL and JS.
I am trying to make widgets to place on our disease pages but I am unable get any data from the feed.
I have tested my YQL statement in the console and it seems to work. Is there something I am missing?
Thank you for your time.

CODEBOX
<html>
<head><title>Test Widget</title>

<script type='text/javascript'>
function ask_mda(o){
var items = o.query.results.askmda.askmdacontent;
var output = '';
var no_items=items.length;
for(var i=0;i<no_items;i++){
var title = items[i].question;
var desc = items[i].answer;
output += "<h3>"+title+"</a></h3>" + desc + "<hr/>";
}
document.getElementById('results').innerHTML = output;
}
</script>
</head>
<body>
<div id='results'></div>
<script src='http://query.yahooapis.com/v1/public/yql?q=select%20askmdacontent.question%2Caskmdacontent.answer%20from%20xml%20where%20url%3D'http%3A%2F%2Ftelethon.mda.org%2Faskmdafeed'%20and%20askmdacontent.disease%20matches%20'.*DMD.*'&format=json&callback=ask_mda'>
</script>
</body>
</html>

by
1 Reply
  • QUOTE (jbehshad @ Sep 30 2010, 12:26 PM) <{POST_SNAPBACK}>
    I am a newbie to YQL and JS.
    I am trying to make widgets to place on our disease pages but I am unable get any data from the feed.
    I have tested my YQL statement in the console and it seems to work. Is there something I am missing?
    Thank you for your time.

    CODE
    <html>
    <head><title>Test Widget</title>

    <script type='text/javascript'>
    function ask_mda(o){
    var items = o.query.results.askmda.askmdacontent;
    var output = '';
    var no_items=items.length;
    for(var i=0;i<no_items;i++){
    var title = items[i].question;
    var desc = items[i].answer;
    output += "<h3>"+title+"</a></h3>" + desc + "<hr/>";
    }
    document.getElementById('results').innerHTML = output;
    }
    </script>
    </head>
    <body>
    <div id='results'></div>
    <script src='http://query.yahooapis.com/v1/public/yql?q=select%20askmdacontent.question%2Caskmdacontent.answer%20from%20xml%20where%20url%3D'http%3A%2F%2Ftelethon.mda.org%2Faskmdafeed'%20and%20askmdacontent.disease%20matches%20'.*DMD.*'&format=json&callback=ask_mda'>
    </script>
    </body>
    </html>



    Hi jbehshad,

    There are two issues with this page.

    1. Since your YQL call has a "'" as part of the URL, you either need to escape it, or enclose them in double quotes. Currently with this script, the call to YQL is not happening. You can take a look at this by installing a firefox plugin called firebug and debugging using it.

    2. The second problem is o.query.results.askmda is an array and not o.query.results.askmda.askmdacontent as per your coding. So doing these change, the following code snippet works fine.

    CODE
    <html>
    <head><title>Test Widget</title>

    <script type='text/javascript'>
    function ask_mda(o){
    var items = o.query.results.askmda;
    var output = '';
    var no_items=items.length;
    for(var i=0;i<no_items;i++){
    var title = items[i].askmdacontent.question;
    var desc = items[i].askmdacontent.answer;
    output += "<h3>"+title+"</a></h3>" + desc + "<hr/>";
    }
    document.getElementById('results').innerHTML = output;
    }
    </script>
    </head>
    <body>
    <div id='results'></div>
    <script src="http://query.yahooapis.com/v1/public/yql?q=select%20askmdacontent.question%2Caskmdacontent.answer%20from%20xml%20where%20url%3D'http%3A%2F%2Ftelethon.mda.org%2Faskmdafeed'%20and%20askmdacontent.disease%20matches%20'.*DMD.*'&format=json&callback=ask_mda">
    </script>
    </body>
    </html>


    Happy Hacking,
    Balaji Narayanan
    0

Recent Posts

in YQL