Wednesday, May 27, 2009

Get Rss data using javascript

Place bellow script in header part

for javascript file go to http://jquery.com

<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript" language=javascript>
$(document).ready(function() {

$.ajax({
type: "GET",
url: "http://yourdomain.com/rss.xml",
dataType: "xml",
success: function(xml) {
$('#update-target').empty();
var str="";

$(xml).find('item').each(function(){

var title = $(this).find('title').text()
var link = $(this).find('link').text()
var desc = $(this).find('description').text()
str +="<tr><td><a href='"+link+"' >"+title+"</a><br />";
str+="<a href='"+link+"' >"+desc.substring(0,100)+"...</a></td></tr>";

}); //close each(
$('#update-target').html(str);
}
}); //close $.ajax(
$("#msg").ajaxError(function(event, request, settings){
$(this).append("Error requesting page " + settings.url + "");
});

}); //close $(
</script>

[/sourcecode]

Place bellow html part in body tab

[sourcecode language="html"]

<Table id='update-target'>

</Table>
<div id=msg></div>

1 comment :

  1. I'm getting "Error requesting page http://www.xul.fr/rss.xml "
    and isn't the link xml because I have tried with others urls

    ReplyDelete

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath