php - xmlDocumentElement is not defined -
here code: html:
<!doctype html> <html> <head> <script type="text/javascript" src="foodstore.js"></script> </head> <body onload="process()"> <h3>welcome our online food store</h3> please type want order: <input type="text" id="userinput" ></input> <div id="underinput"></div> </body> </html>
php
<?php header('content-type: text/xml'); echo"<?xml version='1.0' encoding='utf-8' standalone='yes'?>"; echo '<response>'; $food = $_get['food']; $foodarray = array('tuna','bacon','beef','loaf','mutton'); if(in_array($food,$foodarray)) echo 'we have'.' '.$food; elseif($food=='') echo 'type dude!'; else echo 'sorry dont sell'.' '.$food; echo '</response>'; ?>
js
var xmlhttp = createxmlhttprequestobject(); function createxmlhttprequestobject() { var xmlhttp; if(window.activexobject) { try { xmlhttp = new activexobject("microsoft.xmlhttp"); } catch(e) { xmlhttp = false; } } else if(window.xmlhttprequest) { try { xmlhttp = new xmlhttprequest(); } catch(e) { xmlhttp = false; } } if(!xmlhttp) { alert('cannot connect database!'); } else { return xmlhttp; } } function process() { if(xmlhttp.readystate == 0 || xmlhttp.readystate == 4) { food = encodeuricomponent(document.getelementbyid("userinput").value); xmlhttp.open("get", "ajax.php?food=" + food, true); xmlhttp.onreadystatechange = handleserverresponse; xmlhttp.send(null); } else { settimeout('process()',1000); } } function handleserverresponse() { if(xmlhttp.readystate == 4) { if(xmlhttp.status==200) { xmlresponse = xmlhttp.responsexml; xmldocumnetelement = xmlresponse.documentelement; message = xmldocumentelement.firstchild.data; document.getelementbyid("underinput").innerhtml = "<span style='color:blue'" + message + "</span>"; settimeout('process()',1000); } } else { alert('something went wrong'); } }
everything seems fine me still keep getting error 'xmldocumentelement not defined'. seems error due parsing issues within javascript , php.. please me fix error. thanks
try use
window.settimeout('process', 1000);
Comments
Post a Comment