Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
xml served by CGI script not read by .response.XML

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
genki
New one
New one


Joined: 04 May 2008
Posts: 2

PostPosted: Sun May 04, 2008 5:25 pm    Post subject: xml served by CGI script not read by .response.XML Reply with quote

Hi,

I'm trying to get an automatically updating rss news service one one of my webpages, from the BBC news website. Since I've run into a permissioning problem with downloading an xml file from a remote site with ajax, I've set up a CGI script on my own site that just delivers the remote site xml.

It kind of works... in my ajax javascript, I get a response object and the .responseText contains the full xml from the BBC site. However, when I try to use responseXML on the same response object, it come out blank, so I can't do any parsing with the data.

Any ideas ?

My javascript code is:


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
<script type="text/javascript">
var xmlHttp;

function getXmlHttpObject(){var xmlHttpTemp=null;try{xmlHttpTemp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlHttpTemp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){try{xmlHttpTemp=new XMLHttpRequest();}catch (e){xmlHttpTemp=null;}}}return xmlHttpTemp;}

function getNews(){
if(xmlHttp==null)return;
xmlHttp.open("POST","../cgi-bin/news.cgi",true);
xmlHttp.onreadystatechange=gotNews;
xmlHttp.send(null);
}



function gotNews(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
alert(xmlHttp.responseText);
var xmlDoc=xmlHttp.responseXML.documentElement;
var content="<span style='font-weight: bold; font-size: x-large; color: blue; text-align: center; font-variant: small-caps; text-decoration: underline'><a href='http://news.bbc.co.uk/' target='_blank'>Latest News From BBC News</a></span><br/><br/><ul>";
for(var i=0;i<1;i++){
//content+="<li><a href='"+xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("link")[0].childNodes[0].nodeValue+"' target='_blank'>"+xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a><br/>";
//content+=xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("description")[0].childNodes[0].nodeValue+"<br/><br/>";
}
alert(xmlDoc.xml);
var myTime = new Date();
content+="</ul><small><tt>Updated "+myTime.toLocaleString()+"</tt></small>";
document.getElementById("news").innerHTML=content;
setTimeout("getNews()",1000*60*10);
}}

</script>








</head>
<body onload="xmlHttp=getXmlHttpObject();getNews();">
<div id="news"></div>
</body>
</html>


and my CGI script is:

Code:
#!/usr/bin/perl -w

require "cgi-lib.pl";

use CGI ':standard';
#use CGI::Carp qw(fatalsToBrowser);
$query = new CGI;
print $query->header ( );
$feedurl = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
$timeout = 30;
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("http://www.example.com");
$ua->timeout($timeout);
$req = HTTP::Request->new(GET => "$feedurl");
$res = $ua->request($req);
if ($res->is_success) {
   $tempdata = $res->content;
   #print "Content-Type:application/x-download\n"; 
   #print "Content-Disposition:attachment;filename=$ID\n\n";
   print $tempdata;
}



What comes back from my CGI script looks exactly like what comes back from the BBC rss itself, but I can't use it...

Any ideas
Back to top
View user's profile Send private message
genki
New one
New one


Joined: 04 May 2008
Posts: 2

PostPosted: Thu May 08, 2008 6:56 pm    Post subject: Reply with quote

anyone ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert