javascript - I am not getting output in ajax program when using JSP -


i trying dynamic output using ajax,, "if adds food name ajax works in background , dynamically give me output whether food available or not in array & give according message".but m not getting that.. please refer below image:

html file ::

'<!doctype html> <html> <head> <meta charset="iso-8859-1"> <title>foodstore</title> <script type="text/javascript" src="foodstore.js"></script> </head> <body onload="process()"> <h3> foodstore</h3> enter food want : <input type="text" id="userinput"/> <div id="underinput" /> </body> </html>` 

java script ::

`/** *  */  var xmlhttp = createxmlhttprequestobject();  function createxmlhttprequestobject(){ var xmlhttp; if(window.activexobject){  try{       xmlhttp = new activexobject("microsoft.xmlhttp"); }     catch (e) {         // todo: handle exception          xmlhttp = false;     } }  else{ try{       xmlhttp = new xmlhttprequest;     }     catch (e) {         // todo: handle exception          xmlhttp = false;     } }  if(!xmlhttp)     alert("sorry cannot creat object"); else     return xmlhttp; }  function process(){  if(xmlhttp.readystate==0 || xmlhttp.readystate==4){      var food=encodeuricomponent(document.getelementbyid("userinput").value);      xmlhttp.onreadystatechange= handleserverresponse;     xmlhttp.open("get","foodstore.jsp?food=" +food,true);     xmlhttp.send(null); }else{      settimeout('process()', 1000); } }  function handleserverresponse(){  if(xmlhttp.readystate==4){     if(xmlhttp.status=200){          var xmlresponse = xmlhttp.responsexml;         var xmldocumentelement = xmlresponse.documentelement;         var message = xmldocumentelement.firstchild.data;          document.getelementbyid("underinput").innerhtml = '<span           style="color:blue">'          + message + '</span>';         settimeout('process()', 1000);     }else {         alert('something went wrong!');     } } }` 

jsp::

`<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <%@ page contenttype="text/xml" %>  <response>  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  <c:set var="flag" value="0"></c:set> <c:set var="s" value="${param.food }"></c:set> <c:set var="a" value="${fn:split('grapes,apple,banana', ',')}"       scope="application" /> <c:foreach var="i" begin="0" end="2"> <c:if test="${fn:contains(a[i],s) }"> <c:set var="flag" value="1"></c:set> </c:if> </c:foreach>  <c:if test="${flag eq 0 }"> <c:out value="sorry not have  ${s} !!"></c:out> </c:if>  <c:if test="${param.food eq null }"> <c:out value="plese enter food name!!!"></c:out> </c:if>  <c:if test="${flag eq 1 }"> <c:out value="yes have ${s} !"></c:out> </c:if>  </response>    ` 

thanks in advance :)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -