tanvirtonu
06-17-2009, 09:06 AM
Can anybody tell me why the following code is not working.Only the second function-getCusInfo is working.But amazingly if I put only getCusInfo() function,it works.More amazingly if i put any other function like multiple simple alert functions, they work simultaneously onload.
<script type="text/javascript" >
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
//add body onload events serially
addLoadEvent(getCusName);
addLoadEvent(getCusInfo);
addLoadEvent(function() {
document.body.style.backgroundColor = '#EFDF95';
})
function getXMLHttp()
{
var xmlhttp = false;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
return xmlhttp;
}
function getCusName()
{
//var url="phpdb.php?name="+name+"&city="+city;
xmlhttp=getXMLHttp();
xmlhttp.open("GET","customerdb.php",true);
xmlhttp.onreadystatechange = updateName;
xmlhttp.send(null);
}
function updateName()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response=xmlhttp.responseText;
document.getElementById("showCustomer").innerHTML = response;
}
}
function getCusInfo()
{
xmlhttp=getXMLHttp();
xmlhttp.open("GET","navigateAjax.php",true);
xmlhttp.onreadystatechange = updateCusInfo;
xmlhttp.send(null);
}
function updateCusInfo()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response=xmlhttp.responseText;
document.getElementById("navDiv").innerHTML = response;
}
}
</script>
<script type="text/javascript" >
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
//add body onload events serially
addLoadEvent(getCusName);
addLoadEvent(getCusInfo);
addLoadEvent(function() {
document.body.style.backgroundColor = '#EFDF95';
})
function getXMLHttp()
{
var xmlhttp = false;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
return xmlhttp;
}
function getCusName()
{
//var url="phpdb.php?name="+name+"&city="+city;
xmlhttp=getXMLHttp();
xmlhttp.open("GET","customerdb.php",true);
xmlhttp.onreadystatechange = updateName;
xmlhttp.send(null);
}
function updateName()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response=xmlhttp.responseText;
document.getElementById("showCustomer").innerHTML = response;
}
}
function getCusInfo()
{
xmlhttp=getXMLHttp();
xmlhttp.open("GET","navigateAjax.php",true);
xmlhttp.onreadystatechange = updateCusInfo;
xmlhttp.send(null);
}
function updateCusInfo()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response=xmlhttp.responseText;
document.getElementById("navDiv").innerHTML = response;
}
}
</script>