换句话说,每当用户改变了下拉列表中的值,就会调用 showCD 函数。
XML 文件
XML 文件是"cd_catalog.xml"。该文件中包含了有关 CD 收藏的数据。
JavaScript
这是存储在"selectcd.js"文件中的 JavaScript 代码:
varxmlHttp
functionshowCD(str)
{
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null)
{
alert("BrowserdoesnotsupportHTTPRequest")
return
}
varurl="getcd.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
functionstateChanged()
{
if(xmlHttp.readyState==4||xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
functionGetXmlHttpObject()
{
varxmlHttp=null;
try
{
//Firefox,Opera8.0+,Safari
xmlHttp=newXMLHttpRequest();
}
catch(e)
{
//InternetExplorer
try
{
xmlHttp=newActiveXObject("Msxml2.XMLHTTP");
}
catch(e)