I am using this HTML
<html> <head> <Title>EBAY Search</title> </head> <script language='JavaScript' src='ajaxlib.js'></script> <body> Click here <a href='#' OnClick='GetEmployee()'>link</a> to show content <div id='Result'><The result will be fetched here></div> </body> </html>
With this Javascript
var xmlHttp function GetEmployee() { xmlHttp=GetXmlHttpObject() if(xmlHttp==null) { alert('Your browser is not supported') } var url='get_employee.php' url=url+'cmd=GetEmployee' url=url+'&sid='+Math.random() xmlHttp.open('GET',url,true) xmlHttp.send(null) } function FetchComplete() { if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete') { document.getElementById('Result').innerHTML=xmlHttp.responseText } if(xmlHttp.readyState==1 || xmlHttp.readyState=='loading') { document.getElementById('Result').innerHTML='loading' } } function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp =new ActiveXObject('Microsoft.XMLHTTP'); } } return xmlHttp; }
However it is not being called. get_employee.php works fine when I call it by itself, so that is not the problem. Is there anything wrong in my code that would prevent it from being called? I cannot test with any firefox extensions, I do not have access, so please don’t give that as an answer.
edit: the problem is the javascript is not being called at all. I fixed the question mark problem, but even just a simple javascript with an alert is not being called.
use a javascript debugging tool like firebug, this will make your life simpler.
you had a syntax error in your code that made the error ‘GetEmployee is not defined’
it was a missing ‘catch’ after the last try in ‘GetXmlHttpObject()’. this is the same function after adding the missing ‘catch’.