I wrote C code to get a list of youtube videos for the URL "* http://gdata.youtube.com/feeds/api/standardfeeds/top_rated*" using the libsoup library. I can parse the returned xml data with libxml2 and extract the required fields from it.
I want to know how I can do the same with javascript and display a list in a browser. I have very basic javascript knowledge, but Iām ready to make the necessary effort if you guys point me in the right direction.
I understand the following from the google help documentation for youtube APIs.
- Send the GET request in the desired format to the URL link.
- The answer will be xml or json-c format and this should be parsed
How can I achieve both of them with javascript and display with html / javascript? Sample code or any links will be very helpful.
Edit: adding a php tag for better visibility of the question, and I think php can provide hints for the question.
TIA
Pravein S
EDIT by trying the suggestions below:
How do I debug this? It does not seem to display the name of the video that I intend to credit.
<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("body").append("<div id = 'data'><ul>jffnfjnkj</ul></div>"); $.getJSON("http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?callback=function&alt=jsonc&v=2", function(data) { var dataContainer = $("#data ul"); $.each(data.data.items, function(i, val) { $("body").append("<div id = 'data'><ul>jffnfjnkj</ul></div>"); if (typeof(val.player) !== 'undefined' && typeof(val.title) !== 'undefined') { dataContainer.append("<li><a href = "+val.player.default+" target = '_blank'>"+val.title+"</a></li>"); } }); }); }); }); </script> </head> <body> <h2>Header</h2> <p>Paragrapgh</p> <p>Paragraph.</p> <button>Click me</button> </body> </html>
source share