c# - php code as converted in asp.net not working as expected? -


doing example of ajax, user type in textbox , text continuously posted using javascript , simultanously showing result whether item available or not.

main html as

 <body>             <h3>the chuff bucket </h3>             enter food order:             <input type="text" id="userinput" onfocus="process()"/>             <div id="underinput"/>  </body> 

here code javascript

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 object boss!");     } else         return xmlhttp;  }   function process() {     if (xmlhttp.readystate == 0 || xmlhttp.readystate == 4) {         food = encodeuricomponent(document.getelementbyid("userinput").value);         xmlhttp.open("get", "foodstore.aspx?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;             xmldocumentelement = xmlresponse.documentelement;             message = xmldocumentelement.firstchild.data;              document.getelementbyid("underinput").innerhtml = '<span style = "color:blue;">' + message + '</span>';             settimeout('process()', 1000);         } else {             alert('something went wrong');         }     } } 

the code php working fine is

<?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","mutton","biryani");       if($food == '')          echo 'enter food idiot.';      else{          if(in_array($food,$foodarray))           echo 'we have '.$food.'!';          else           echo 'we not sell '.$food.'!';      } echo '</response>'; ?> 

but when converted asp.net postback , and working not showing reult inside div. main cause figure out relating echo lines

protected void page_load(object sender, eventargs e)         {             response.contenttype = "text/xml";             system.diagnostics.debug.print("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>");             system.diagnostics.debug.print("<response>");             string food = (string)request.querystring["food"];              string[] foodarray = new string[] { "tuna", "beef", "mutton", "fish","biryani" };              if (string.isnullorempty(food))             {                 system.diagnostics.debug.print("enter food idiot.");             }             else              {                 if (foodarray.contains(food))                 {                     system.diagnostics.debug.print("we serve " + food);                 }                 else                  {                     system.diagnostics.debug.print("we not serve " + food);                 }             }              system.diagnostics.debug.print("</response>");          } 

note: have tried instead of print response.write result same div id=underinput not getting result. here please.

make sure have replaced system.diagnostics.debug.print response.write. then, check html markup on foodstore.aspx.

foodstore.aspx should have @page directive, nothing else.. want return xml content, need make sure there no doctype or html elements on page.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -