﻿// handle xmlhttpreques
function ajreq(strfunc, strparam, strReturn, strpage) {
    //get 
    var func = strfunc;
    var params = "?" + "func=" + func + strparam;
    var page = strpage;
    var pageparams = page + params;
    //first parameter is to specify Method either GET or POST
    //second parameter is URL of server, where you want to send request
    //Third parameter would define either communication pattern is synchornous(false) or asynchornous(true)
    xmlHttp.open("GET", pageparams, true);
    //GetWeather.aspx is include in sample, which is intermediate between your request and web service. 

    //send request to server according to parameters    

    //defining function to call whenever xmlhttp state changes        
    xmlHttp.onreadystatechange = function() {
        //if request has been entertained and response is returned from server
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            //show contents of the response using responseText property of xmlHttp obj
            document.getElementById(strReturn).innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.send(null);
}

// handle xmlhttpreques
function ajreqPOST(strfunc, strparam, strReturn, strpage, callback) {
    //get 
    var func = strfunc;
    var params = "func=" + strfunc + strparam;
    var page = strpage;
    //first parameter is to specify Method either GET or POST
    //second parameter is URL of server, where you want to send request
    //Third parameter would define either communication pattern is synchornous(false) or asynchornous(true)
    xmlHttp.open("POST", page, false);
    //GetWeather.aspx is include in sample, which is intermediate between your request and web service.
    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //defining function to call whenever xmlhttp state changes
    xmlHttp.onreadystatechange = eval(callback);
    xmlHttp.send(params);
}

