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")
    开源学习,互动进步
  • 相关阅读:
    《JAVA多线程编程核心技术》 笔记:第四章、Lock的使用
    服务器负载粗略估算
    spring事务传播性理解
    BlockingQueue 阻塞队列2
    六大原则
    mycat之schema.xml理解
    mycat分库读写分离原理
    sqlservere连接问题
    java代码添加mysql存储过程,触发器
    Amoeba+Mysql实现读写分离+java连接amoeba
  • 原文地址:https://www.cnblogs.com/L0VEGP/p/5426513.html
Copyright © 2011-2022 走看看