zoukankan      html  css  js  c++  java
  • 处理返回结果(XML)

    var xmlHttp
    
    function showUser(str)
     { 
     xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
      {
      alert ("Browser does not support HTTP Request")
      return
      } 
     var url="responsexml.php"
     url=url+"?q="+str
     url=url+"&sid="+Math.random()
     xmlHttp.onreadystatechange=stateChanged 
     xmlHttp.open("GET",url,true)
     xmlHttp.send(null)
     }
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {

    //返回的是一个xml xmlDoc=xmlHttp.responseXML; document.getElementById("firstname").innerHTML= xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue; document.getElementById("lastname").innerHTML= xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue; document.getElementById("job").innerHTML= xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue; document.getElementById("age_text").innerHTML="Age: "; document.getElementById("age").innerHTML= xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue; document.getElementById("hometown_text").innerHTML="<br/>From: "; document.getElementById("hometown").innerHTML= xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue; } } function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp }

    后台注意:

    //设置xml
    header('Content-Type: text/xml'); header("Cache-Control: no-cache, must-revalidate"); //A date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT")
    开源学习,互动进步
  • 相关阅读:
    Ecshop屏幕wap
    SQLite命令
    初识SQLite
    last_insert_id()
    php中的全局变量global(低级错误啊)
    在搜索框加入语音搜索
    解压zip文件出现bash:unzip:commond not found
    DataView.RowFilter使用
    设计自己的模板引擎(一)模板替换中的嵌套循环处理
    没完没了的Cookie,读懂asp.net,asp等web编程中的cookies 
  • 原文地址:https://www.cnblogs.com/L0VEGP/p/5426513.html
Copyright © 2011-2022 走看看