tags:

views:

134

answers:

3
A: 

try this:

$.get('http://digg.com/rss/index.xml', {}, callback, 'xml');

callback is the function you've already written.

what you've missed is the http:// part. I just added the 4th arg for a measure of safety, just in case the url does not return an appropriate MIME type.

Here Be Wolves
Unfortunately replacing my $.get line with this breaks the thing completely - blank page.
Sean McRaghty
A: 

"digg.com/rss/index.xml" redirects to "http://feeds.digg.com/digg/popular.rss", try to change the URL.

JS + HTML:

...
// Build an HTML string

    myHTMLOutput = '<table width="98%" border="1" cellpadding="0" cellspacing="0">';
    myHTMLOutput += '<thead><th>Title</th><th>PubDate</th><th>Description</th><th>Link</th></thead>';

    // Run the function for each student tag in the XML file
    myHTMLOutput += '<tbody>'
    $('item',xml).each(function(i) {
        // Build row HTML data and store in string
        myHTMLOutput += BuildDiggHTML(this);
    });
    myHTMLOutput += '</tbody></table>';
...


function BuildDiggHTML(el){

    // Build HTML string and return
    var output = '';

    output  = '<tr>';
    try { 
      output += '<td>'+ $(el).find("title").text() +'</td>';
      output += '<td>'+ $(el).find("pubDate").text() +'</td>';
      output += '<td>'+ $(el).find("description").text() +'</td>';
      output += '<td>'+ $(el).find("link").text() +'</td>';
    }catch(ex){
      output = '<td colspan="4">'+ex.description+'</td>';
    }        
    output += '</tr>';
    return output;
}

EDIT:

jQuery Ajax Cross-Domain

andres descalzo
Hi - I've changed the code (which I've included in my original post), but I still have exactly the same results! Thanks for your reply; any more ideas though?
Sean McRaghty
@Sean McRaghty Excuse me, but I made a mistake in the answer, you're doing cross-domain, this work in IE but will not work in other browsers. I pass a link in the answer for you to see a solution to this problem
andres descalzo
A: 

You can't just do a call to digg.com... that's a cross-domain request. You'll need to do the whole jsonp (jQuery docs that mention it) thing or just do this data gathering on your backend.

Also, just as a side note, you should get in the habit of doing:

var someContent = [];
...
someContent.push( "somestring" );
...
someContent.join('');

...instead of...

var someContent = '';
...
someContent += "somestring";

becuase you will find it much faster.

thenduks