The following javascript code does not work .Not able to figure out the reason.Cud anyone help plz

<html>

<head>
<title>AJAX RSS Reader</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<script language="javascript"  type="text/javascript">

var RSSRequestObject = false; // XMLHttpRequest Object
var Backend = 'http://www.google.fr/news?hl=en&ned=en&q=ajax&ie=UTF-8&output=rss'; // Backend url
window.setInterval("update_timer()", 1200000); // update the data every 20 mins


if (window.XMLHttpRequest) // try to create XMLHttpRequest
	RSSRequestObject = new XMLHttpRequest();

if (window.ActiveXObject)	// if ActiveXObject use the Microsoft.XMLHTTP
	RSSRequestObject = new ActiveXObject("Microsoft.XMLHTTP");


/*
* onreadystatechange function
*/
function ReqChange() {

	// If data received correctly
	if (RSSRequestObject.readyState==4) {

		// if data is valid
		if (RSSRequestObject.responseText.indexOf('invalid') == -1)
		{
			// Parsing RSS
			var node = RSSRequestObject.responseXML.documentElement;


			// Get Channel information
			var channel = node.getElementsByTagName('channel').item(0);
			var title = channel.getElementsByTagName('title').item(0).firstChild.data;
			var link = channel.getElementsByTagName('link').item(0).firstChild.data;

			content = '<div class="channeltitle"><a href="'+link+'">'+title+'</a></div><ul>';

			// Browse items
			var items = channel.getElementsByTagName('item');
			for (var n=0; n < items.length; n++)
			{
				var itemTitle = items[n].getElementsByTagName('title').item(0).firstChild.data;
				var itemLink = items[n].getElementsByTagName('link').item(0).firstChild.data;
				try
				{
					var itemPubDate = '<font color=gray>['+items[n].getElementsByTagName('pubDate').item(0).firstChild.data+'] ';
				}
				catch (e)
				{
					var itemPubDate = '';
				}


				content += '<li>'+itemPubDate+'</font><a href="'+itemLink+'">'+itemTitle+'</a></li>';
			}


			content += '</ul>';
			// Display the result
			document.getElementById("ajaxreader").innerHTML = content;

			// Tell the reader the everything is done
			document.getElementById("status").innerHTML = "Done.";

		}
		else {
			// Tell the reader that there was error requesting data
			document.getElementById("status").innerHTML = "<div class=error>Error requesting data.<div>";
		}

		HideShow('status');
	}

}

/*
* Main AJAX RSS reader request
*/
function RSSRequest() {

	// change the status to requesting data
	HideShow('status');
	document.getElementById("status").innerHTML = "Requesting data ...";

	// Prepare the request
	RSSRequestObject.open("GET", Backend , true);
	// Set the onreadystatechange function
	RSSRequestObject.onreadystatechange = ReqChange;
	// Send
	RSSRequestObject.send(null);
}

/*
* Timer
*/
function update_timer() {
	RSSRequest();
}


function HideShow(id){
	var el = GetObject(id);
	if(el.style.display=="none")
	el.style.display='';
	else
	el.style.display='none';
}

function GetObject(id){
	var el = document.getElementById(id);
	return(el);
}

</script>

<body onload="RSSRequest();">

<h2>AJAX RSS Reader</h2>
<div id="status" style="display:none"></div>
<div id="ajaxreader"></div>

</body>

</html>

is it the right forum

Java != JavaScript moving to correct forum

Gear26926,

It works fine in IE6 and may also work in the even older IE5 but won't work in any other browser unless served from google.fr .

Reason: Most browsers block AJAX calls to "foreign" (ie 3rd party) domains.

Solution: Sticking with 100% client-side code .... I wish I knew. I developed a nice little AJAX application for my own use recently and would like to share it with some friends but can't because they have all moved on from IE6. I have explored using Opera Unite as a proxy but haven't managed to get it to work yet. Ultimately, you can server the page from your own server (either local or remote) such that a script (eg PHP) performs an equivalent to the AJAX request and serves your page with the links already in place. But then you need (a) IIS/Apache/etc on your home computer or a rented server account (ISP web-spaces are seldom script enabled), and (b) the right know-how.

Airshow

Airshow, Thanks for the reply.
You are correct.This code does not work in any browser with any url example.Cud u let me know what is the issue for it to work in firefox 3.5.
I am not supposed to use php code.Is there any way to make this code work with IE and firefox.Plz let me know at the earliest

Gear,

I wish I knew. As I said, anything other than IE5 and IE6 will not do cross-domain AJAX.

For displaying a regular HTML page, I would suggest using an iframe but you can't do that with RSS (which is XML).

So unless someone posts something here that I don't yet know, then we are both stuck. I still think using Opera Unite as a proxy might be a way ahead but I've been trying that on and off for the last 2 months and have made little progress.

Sorry it's not good news.

Airshow

The JavaScript Source is your resource for thousands of free JavaScripts for cutting and pasting into your Web pages.

For displaying a regular HTML page, I would suggest using an iframe but you can't do that with RSS (which is XML).

I should have said, "but you can't do that with RSS (which is XML) unless the feed comes ready-styled (with eg. XSLT)".

Unfortunately, you're still out of luck because the feed you are interested in, is not styled.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.