ericaalicen
Programmer
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.
The above example is w/out passing the third variable. Below is how I've been trying to pass it.
I'm totally stuck and out of ideas. I appreciate any help or guidance here.
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.