joshbgood
05-25-2009, 02:05 PM
I'm trying to fill out this DIV1 area (bottom of the HTML file) with simple name query form.
<FORM METHOD="GET">
<input type="text" name="searchemployee" id="searchemployee" />
<input type="button" value="Search" onClick="getEmployee ();" />
</FORM>
< DIV ID="div1">
<span id="employee_name"> </span><BR>
<span id="phone"> </span><BR>
<span id="position"> </span><BR>
</DIV>
My PHP file yields this XML, so I don't think it's where the problem is:
<searchemployee>
<employee_name>Jenny Smith</ employee_name>
<phone>867-5309</phone>
<position>Manager</ position>
</searchemployee>
And my JS is inside the head of the HTML file, as seen below. I've read many of the posts on this issue (ResponseXML, etc.) & followed all the advises on the function UPDATE part, even tried every other possible variations, to no result. I'm pretty sure, it's due to some minor dumb typo, but after 6 hours playing with this, I still can't find where the problem is. Help!!
var xmlhttp;
function getEmployee(){
xmlhttp = getXMLHTTPRequest();
if (xmlhttp == null) {
alert("Browser does not support HTTP Request");
return;
}
var url = " getEmployee.php";
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = update;
xmlhttp.send(null);
}
function update(){
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
xmlDoc = xmlhttp.responseXML;
document.getElementById("employee_name").innerHTML = xmlDoc.getElementsByTagName("employee_name")[0];
}
}
}
function GetXmlHttpObject(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
<FORM METHOD="GET">
<input type="text" name="searchemployee" id="searchemployee" />
<input type="button" value="Search" onClick="getEmployee ();" />
</FORM>
< DIV ID="div1">
<span id="employee_name"> </span><BR>
<span id="phone"> </span><BR>
<span id="position"> </span><BR>
</DIV>
My PHP file yields this XML, so I don't think it's where the problem is:
<searchemployee>
<employee_name>Jenny Smith</ employee_name>
<phone>867-5309</phone>
<position>Manager</ position>
</searchemployee>
And my JS is inside the head of the HTML file, as seen below. I've read many of the posts on this issue (ResponseXML, etc.) & followed all the advises on the function UPDATE part, even tried every other possible variations, to no result. I'm pretty sure, it's due to some minor dumb typo, but after 6 hours playing with this, I still can't find where the problem is. Help!!
var xmlhttp;
function getEmployee(){
xmlhttp = getXMLHTTPRequest();
if (xmlhttp == null) {
alert("Browser does not support HTTP Request");
return;
}
var url = " getEmployee.php";
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = update;
xmlhttp.send(null);
}
function update(){
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
xmlDoc = xmlhttp.responseXML;
document.getElementById("employee_name").innerHTML = xmlDoc.getElementsByTagName("employee_name")[0];
}
}
}
function GetXmlHttpObject(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}