I have sent data from process()
function to router.get
method.But I can't pass my xmlString
variable of router.get
method to handleServerResponse()
method in test.js.It's showing internal server error.Please fix my problem.Thanks in advance.
my test.js
file
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = false;
}
}else{
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}
if(!xmlHttp){
alert("Cant create that object");
}else{
return xmlHttp;
}
}
function process(){
if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
var food = document.getElementById("userInput").value;
console.log(food);
xmlHttp.open("GET", "/start/" + food, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
} else {
setTimeout('process()', 1000);
}
}
function handleServerResponse(){
let xmlResponse;
let xmlDocumentElement;
let message;
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
console.log("check done");
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild;
console.log(message);
document.getElementById("underInput").innerHTML = '<span style="color:blue"></span>';
setTimeout('process()', 1000000);
} else {
alert('Something went wrong!');
}
}
}
my index.js
file
router.get('/start/:id', function(req, res, next) {
console.log(req.params.id);
var xmlString = "<div id='foo'><a href='#'>Hello BigGo</a><span></span></div>"
, parser = new DOMParser()
, doc = parser.parseFromString(xmlString, "text/xml");
var data='dip';
});
my add.hbs
file
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body >
<h3>The Chuff Bucket</h3>
Enter the foood you would like to order:
<input type="text" id="userInput" oninput="process()" />
<div id="underInput"></div>
</body>
</html>