Ajax:xmlhttp.responseText响应显示完整的内部HTML而不是必需的文本

时间:2014-04-02 07:29:51

标签: javascript ajax

这是我正在使用的Ajax函数但是在调用函数之后,它会在HTML标记+ required_text中给出响应。

值变量的响应 “

<br/>
 <font size='1'>
  <table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
   <tr>
     <th align='left' bgcolor='#f57900' colspan="5">
       <span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>
         ( ! )
       </span> 
        Notice: Undefined index: raw_id in C:\wamp\www\ajax\jsvarupdat\remote.php on line         
         <i>
            3
         </i>
     </th>
   </tr>
 </table>
< /font>

丹尼尔“

值变量

中需要

“丹尼尔”

function call_funct(str){ 

if (str=="")
  {
  document.getElementById("scat").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
value = xmlhttp.responseText;
    }
  }

xmlhttp.open("post","remote.php?raw_id"+str,true);
xmlhttp.send();  
}

1 个答案:

答案 0 :(得分:1)

您的代码存在的问题是您没有在=

上使用xmlhttp.open("post","remote.php?raw_id"+str,true);

您的代码应该像 -

function call_funct(str){ 

   if (str=="")
    {
          document.getElementById("scat").innerHTML="";
          return;
    }
  if (window.XMLHttpRequest)
   {
     xmlhttp=new XMLHttpRequest();
   }
  else
   {
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.onreadystatechange=function()
  {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
       value = xmlhttp.responseText;
     }
  }

 xmlhttp.open("post","remote.php?raw_id="+str,true);
 xmlhttp.send();  
}