﻿
///#########################################################///
///======= This is a default AJAX function of DOM ==========///
///======= Developed at Esolz Technolozies Pvt. Ltd. =======///
///#########################################################///

//========================================================================================//
///#################### Parameter Description ##############///
///     'httpMethod' ---------> 'POST' or 'GET'
///     'url' ----------------> 'url of server side page'
///     'data' ---------------> 'Queary String' i.e: "dC=" + dC + "&fG=" + fG + "&dA=" + dA + "&eA=" + eA
///     'responseType' -------> 'TEXT' or 'XML'
///#########################################################///


var xmlHttpDB = null;
var esolzResponseXML = null;
var esolzResponseTEXT = null;
var rspText = null;

function esolzAJAX(httpMethod, url, data, responseType)
{
    try
    {
        try
        {
            xmlHttpDB = new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                xmlHttpDB = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(err)
            {
                alert("This browser is not 'XMLHttp' compatible!");
                return;
            }
        }
        if(httpMethod == "POST" || httpMethod == "post")
        {
            xmlHttpDB.open("POST", url, true);
            xmlHttpDB.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttpDB.send(data);
        }
        else if(httpMethod == "GET" || httpMethod == "get")
        {
            xmlHttpDB.open("GET", url, true);
            xmlHttpDB.send(data);
        }
        xmlHttpDB.onreadystatechange = onStateChanged;
        
        if(responseType == 'TEXT')
        {
            return xmlHttpDB.responseText;
        }
        else if(responseType == 'XML')
        {
            return xmlHttpDB.responseXML.documentElement;
        }
        else
        {
            return 'No Response from Server!';
        }
    }
    catch(Error)
    {
        alert(Error);
    }
}
    function onStateChanged()
    {
        try
        {
            if (xmlHttpDB.readyState == 4)
            {
                if(xmlHttpDB.responseXML != null)
                {
                    esolzResponseXML = xmlHttpDB.responseXML.documentElement;
                }
                else if(xmlHttpDB.responseText != null)
                {
                    rspText = xmlHttpDB.responseText;
                }
            }
        }
        catch(Error)
        {
            alert(Error);
        }
    }

