Показать сообщение отдельно

  #4  
Старый 25.08.2008, 20:25
nc.STRIEM
Members of Antichat - Level 5
Регистрация: 05.04.2006
Сообщений: 1,066
Провел на форуме:
3493315

Репутация: 1228


Отправить сообщение для nc.STRIEM с помощью ICQ
По умолчанию

небольшой набор функций для работы с ajax
PHP код:
// (c) nc.STRIEM

var resultId;

function 
getXmlHttp()
{
    var 
xmlhttp;
    try 
    {
        
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (
e
    {
        try 
        {
            
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (
E
        {
            
xmlhttp false;
        }
    }
    if (!
xmlhttp && typeof XMLHttpRequest != 'undefined'
        
xmlhttp = new XMLHttpRequest();

    return 
xmlhttp;
}

function 
sendRequest(url_resultIdmethodquery)
{    
    
resultId _resultId;
    var 
httpRequest getXmlHttp();
    var 
timeout;
    if(
method == null)
        
method 'GET';
    
window.document.getElementById(resultId).innerHTML '<center><img src="img/load.gif"></center>';
    
httpRequest.open(methodurltrue);
    
    
httpRequest.onreadystatechange = function()
    {
        if (
httpRequest.readyState != 4)
            return;
        
clearTimeout(timeout);
        if (
httpRequest.status == 200)    
            
window.document.getElementById(resultId).innerHTML httpRequest.responseText;
        else 
            
handleError(httpRequest.statusText);
    }
    
    if(
query != null)
        
httpRequest.setRequestHeader('Content-Type''application/x-www-form-urlencoded')
    
httpRequest.send(query);


    
timeout setTimeout( function(){ httpRequest.abort(); handleError("Time over");}, 10000);  // таймаут
    
return false;
}

function 
GetContents(urlmethodquery)
{
    var 
httpRequest getXmlHttp();
    var 
timeout;
    if(
method == null)
        
method 'GET';
    
httpRequest.open(methodurlfalse);
    if(
query != null)
        
httpRequest.setRequestHeader('Content-Type''application/x-www-form-urlencoded')
    
httpRequest.send(query);
    if (
httpRequest.status == 200)    
            return 
httpRequest.responseText;
    return 
httpRequest.status+' '+httpRequest.statusText;
}    

function 
handleError(message
{
    
window.document.getElementById(resultId).innerHTML message;
}

function 
element(id)
{
    return 
encodeURIComponent(window.document.getElementById(id).value);

пример использования http://taran.su/guest/
 
Ответить с цитированием