html tags not working inside response tags AJAX PHP -


i have working code, using ajax, when user types input box, output 'hello' on screen without having press enter. however, there problem. let me show part of working code first:

<?php  include('head.php');  echo "<response>";  echo "hello";  echo "</response>";  ?> 

^---the above code works, , outputs 'hello' on screen whenever user types in input box. code input box, , else on separate files, , not shown unless requested. problem cannot use html tags inside response tags:

<?php  include('head.php');  echo "<response>";  echo "<i>"."hello"."</i>";  echo "</response>";  ?> 

^---the above code output word 'undefined', instead of word 'hello' in italics. don't know why it's doing that, if know why, , how fix this, or if there workaround problem, please let me know. thank you.

edit: requested show part of code ajax, in separate file called test5.html:

<?php  include('ajax.php');  ?>  <html> <body> <input type="text" id="userinput" onkeyup = "process('userinput','output','foodstore.php')"/> <div id="output" /> </body> </html> 

more code in file called ajax.php:

<script type = "text/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 !") } else return xmlhttp; }  function process(text,output,link){  //text = 'userinput';  if(xmlhttp.readystate==0 || xmlhttp.readystate==4){ food = encodeuricomponent(document.getelementbyid(text).value); xmlhttp.open("get", link+food,true);  xmlhttp.onreadystatechange = function() { handleserverresponse(text,output,link); };  xmlhttp.send(null); }else{ settimeout("process(text,output,link)",1000);//cekaj 1s pa probaj opet } }  function handleserverresponse(text,output,link){  if(xmlhttp.readystate==4){  if(xmlhttp.status==200){     xmlresponse = xmlhttp.responsexml; //izvlaci se xml sto smo dobili     xmldocumentelement = xmlresponse.documentelement;     message = xmldocumentelement.firstchild.data;     document.getelementbyid(output).innerhtml = message;  settimeout(function() {     process(text,output,link); }, 1000);  }else{     //alert('someting went wrong !'); } } }  </script> 

how sending data response tag?

you should use .html

your success function should this:

function(data) { $('response').html(data); }

update: xml content has update include html within.

<![cdata[<i>hello</i>]]>


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -