Ajax POST method, using xmlhttprequest

To post data using ajax xmlhttp protocol.

        var request;
        function createAjax(url,callbackfunction,parameters,method)
        {
            try
            {
                request = new ActiveXObject("Microsoft.XMLHTTP")


;

            }
            catch(e1)
            {
                try
                {
                    request = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e2)
                {
                    try
                    {
                        request = new XMLHttpRequest();
                    }
                    catch(e3)
                    {
                        alert("Error initializing XmlHttp object!!!");
                    }
                }
            }

            request.open(method,url,true)
            request.onreadystatechange = callbackfunction;
            if(method == "POST")
            {
                request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                request.setRequestHeader("Content-length", parameters.length);
                request.setRequestHeader("Connection", "close");
            }
            request.send(parameters);
        }
Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*