Cybercrux

Everything is achievable through technology

ajax common function

function ajaxpage(Process, url, containerid) {
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject) {
try { page_request = new ActiveXObject("Msxml2.XMLHTTP") }
catch (e) {
try { page_request = new ActiveXObject("Microsoft.XMLHTTP") }
catch (e) { }
}
}
page_request.onreadystatechange = function () {
if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
switch (Process) {
case 'city':
loadcity(page_request, containerid)
break;}
}
}
page_request.open('GET', url, false)
document.body.style.cursor = "auto"; page_request.send(null);
}
function loadcity(page_request, containerid) {
var City = document.getElementById('drpcity');
City.options.length = 0; //reset
var optn = document.createElement("OPTION");
optn.text = "—-Select City--"; //add select
optn.value = "0";
City.options.add(optn);
var TempCity = page_request.responseText.split(",");//dynamic states
for (var j = 0; j < TempCity.length; j++) {
var optn = document.createElement("OPTION");
optn.text = TempCity[j];
optn.value = TempCity[j];
City.options.add(optn);
}
}
function LoadCityDpd() {
var State = document.getElementById('drpstate');
var Statetmp = State.options[State.selectedIndex].value;
var url = 'ajaxcity.aspx?state=' + Statetmp;
ajaxpage('', url, '');
}

One thought on “ajax common function

Leave a comment