Kullanıcı:Volkan/httprequest.js

Vikipedi, özgür ansiklopedi
Not: Sayfayı kaydettikten sonra değişiklikleri görebilmek için tarayıcınızın önbelleğinizi temizlemeniz gerekir. Google Chrome, Firefox, Microsoft Edge ve Safari: ⇧ Shift tuşuna basılı tutun ve Yeniden Yükle araç çubuğu düğmesine tıklayın. Ayrıntılar ve diğer tarayıcılara yönelik yönergeler için Vikipedi:Önbelleğinizi atlayın sayfasını inceleyin.
    function createXmlHttpRequest() 
    {
        if (window.XMLHttpRequest) 
        {
            xmlhttpobj = new XMLHttpRequest();
        } 
        else 
        {
            try 
            {
                xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) 
            {
                try 
                {
                    xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
                }  
                catch (e) 
                {
                    xmlhttpobj = null;
                }
            }
        }
        return xmlhttpobj;
    }
    function httpRequest(url, post, headers, asyncHandler)
    {
        var async = false;
        var request = createXmlHttpRequest();
        if (asyncHandler)
        {
            async = true;
            request.onreadystatechange = asyncHandler;
        }
        request.open(post ? "POST":"GET", url, async);
        for(header in headers)
        {
            request.setRequestHeader(header,headers[header]);
        }
        request.send(post||null);        
        return request;
    }