evie
08-11-2007, 03:36 PM
I am trying to implement a search function with Ajax and PHP when clicking a button, a hidden div showing the results of a database query should be shown. Technically, the code is following:
HTML: <input type="button" onclick="JavaScript:showresults(search_ing.value)" value="search">
JavaScript:
function showresults(item_name)
{
xmlHttp=GetXmlHttpObject()
var url="/manager/ingredients/showresults.php"
url=url+"?item_name="+item_name
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("result").style.display="block";
document.getElementById("result").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
However, I have a continuing problem in IE. An alert message pops up stating:Unknown JavaScript Error, indicating the line i have made bold in the code?
new ActiveXObject("Msxml2.XMLHTTP") instead of new ActiveXObject("Microsoft.XMLHTTP") but that was no help... Please help me!
HTML: <input type="button" onclick="JavaScript:showresults(search_ing.value)" value="search">
JavaScript:
function showresults(item_name)
{
xmlHttp=GetXmlHttpObject()
var url="/manager/ingredients/showresults.php"
url=url+"?item_name="+item_name
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("result").style.display="block";
document.getElementById("result").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
However, I have a continuing problem in IE. An alert message pops up stating:Unknown JavaScript Error, indicating the line i have made bold in the code?
new ActiveXObject("Msxml2.XMLHTTP") instead of new ActiveXObject("Microsoft.XMLHTTP") but that was no help... Please help me!