Тема: AJAX function
Показать сообщение отдельно
  #2 (permalink)  
Старый 29.12.2011, 23:38
что-то знаю
Отправить личное сообщение для devote Посмотреть профиль Найти все сообщения от devote
 
Регистрация: 24.05.2009
Сообщений: 5,176

function read( src, callback ) {
    var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    xhr.onreadystatechange = function() {
        if ( this.readyState == 4 && this.status == 200 ) {
            xhr.onreadystatechange = null;
            callback( xhr.responseText, xhr );
        }
    }
    xhr.open( "GET", src, true );
    xhr.send( null );
}

read( 'http://mySite.com/text.txt', function( data ){
    alert( data );
});
Ответить с цитированием