Показать сообщение отдельно
  #6 (permalink)  
Старый 11.06.2012, 01:35
что-то знаю
Отправить личное сообщение для devote Посмотреть профиль Найти все сообщения от devote
 
Регистрация: 24.05.2009
Сообщений: 5,176

<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'] );
    }

?>
__________________
хм Russians say завтра but завтра doesn't mean "tomorrow" it just means "not today."
HTML5 history API рассширение для браузеров не поддерживающих pushState, replaceState
QSA CSS3 Selector Engine

Последний раз редактировалось devote, 11.06.2012 в 01:45.
Ответить с цитированием