Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error passing dynamically generated layer name to stateChanged()

Status
Not open for further replies.

ericaalicen

Programmer
Dec 20, 2001
53
US
I am a newbie to Ajax. I modified the script below to use 3 variables instead of 1. The first two I have managed to successfully append to the url of the page being called in the script. The third variable I need to pass from showParts() to stateChanged() but when I try to pass it it gives me a readystate error. I need to be able to pass a dynamically generated layer name.

Code:
var xmlHttp

function showParts(str,year,divname)
{ 
var url="getParts.cfm?pid=" + str + "&carYear=" + year
xmlHttp=GetXmlHttpObject(stateChanged)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
} 
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
}

The above example is w/out passing the third variable. Below is how I've been trying to pass it.

Code:
var xmlHttp

function showParts(str,year,divname)
{ 
var url="getParts.cfm?pid=" + str + "&carYear=" + year
xmlHttp=GetXmlHttpObject(stateChanged(divname))
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
} 

function stateChanged(div) 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById(div).innerHTML=xmlHttp.responseText 
} 
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
}

I'm totally stuck and out of ideas. I appreciate any help or guidance here.
 
This is the error I'm getting when passing the third variable:

xmlHttp.readystate is null or not an object
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top