<div id="info"></div>
<script type="text/javascript">
function ajax( url, callback ) {
var req = new XMLHttpRequest();
req.open( 'GET', url, true );
req.onreadystatechange = function() {
if ( req.readyState === 4 ) {
if ( req.status >= 200 && req.status < 300 || req.status === 304 ) {
callback && callback( req.responseText, this.responseXML );
} else {
throw new Error( 'not found' );
}
}
}
req.send( null );
}
var nocache = "&nocache=" + Math.random()*1000000,
url = "rss.news.yahoo.com/rss/topstories";
ajax( "xmlget.php?url=" + url + nocache, function( data, xml ) {
var out = '';
if ( xml != null ) {
var titles = xml.getElementsByTagName('title');
for ( var j = 0; j < titles.length; ++j ) {
out += titles[j].childNodes[0].nodeValue + '<br />'
}
document.getElementById('info').innerHTML = out;
} else {
document.getElementById('info').innerHTML = "Что-то не то получили: " + data;
}
});
</script>
и PHP выглядит так:
<?php
if ( isset( $_GET['url'] ) ) {
if ( ini_get( 'magic_quotes_gpc' ) == 1 ) {
$_GET['url'] = stripslashes( $_GET['url'] );
}
header('Content-Type: text/xml');
echo file_get_contents( "http://".$_GET['url'] );
}
?>