新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 讨论HTML、XHTML、Web2.0、Ajax、XUL, ExtJS, jQuery, JSON、Social Networking System(SNS)、Rich Internet Applications (RIA)、Tagging System、Taxonomy(tagsonomy,folkonomy)、XForms、XFrames、XInclude, XBL (XML Binding Language)等话题
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』 → 摘抄:Using the XML HTTP Request object 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 57702 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 摘抄:Using the XML HTTP Request object 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     Qr 帅哥哟,离线,有人找我吗?
      
      
      威望:9
      等级:博士二年级(版主)
      文章:4392
      积分:29981
      门派:XML.ORG.CN
      注册:2004/5/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Qr发送一个短消息 把Qr加入好友 查看Qr的个人资料 搜索Qr在『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』的所有贴子 访问Qr的主页 引用回复这个贴子 回复这个贴子 查看Qr的博客楼主
    发贴心情 摘抄:Using the XML HTTP Request object

    1、Creating the object

    In Internet Explorer, you create the object using new ActiveXObject("Msxml2.XMLHTTP") or new ActiveXObject("Microsoft.XMLHTTP") depending on the version of MSXML installed. In Mozilla and Safari (and likely in future UA's that support it) you use new XMLHttpRequest() IceBrowser uses yet another method the window.createRequest() method.

    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
    }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp=false;
    }
    }
    if (!xmlhttp && window.createRequest) {
    try {
      xmlhttp = window.createRequest();
    } catch (e) {
      xmlhttp=false;
    }
    }

    2、How do I make a request?
    xmlhttp.open("GET", "test.txt",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       alert(xmlhttp.responseText)
      }
    }
    xmlhttp.send(null)

    3、Making a HEAD request

    xmlhttp.open("HEAD", "/faq/index.html",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       alert(xmlhttp.getAllResponseHeaders())
      }
    }
    xmlhttp.send(null)


    4、Using HEAD requests, to find the Last-Modified of another file.

    xmlhttp.open("HEAD", "/faq/index.html",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       alert("File was last modified on - "+
        xmlhttp.getResponseHeader("Last-Modified"))
      }
    }
    xmlhttp.send(null)


    5、Does a url exist?
    xmlhttp.open("HEAD", "/faq/index.html",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       if (xmlhttp.status==200) alert("URL Exists!")
        else if (xmlhttp.status==404) alert("URL doesn't exist!")
         else alert("Status is "+xmlhttp.status)
      }
    }
    xmlhttp.send(null)

    6、Calling a server-side Script without refreshing the page

    <%
    a=+(Request.QueryString('a')+'')
    b=+(Request.QueryString('b')+'')
    if (isNaN(a) || isNaN(b)) {a='';b='';total='' }
      else {
       total=a+b
      }
    acc=Request.ServerVariables('HTTP_ACCEPT')+''
    if (acc.indexOf('message/x-jl-formresult')!=-1) {
      Response.Write(total)
    } else {
    %>
    <script src="xmlhttp.js" type="text/javascript"></script>
    <script>
    function calc() {
      frm=document.forms[0]
      url="add.1?a="+frm.elements['a'].value+"&b="+frm.elements['b'].value
      xmlhttp.open("GET",url,true);
      xmlhttp.onreadystatechange=function() {
       if (xmlhttp.readyState==4) {
        document.forms[0].elements['total'].value=xmlhttp.responseText
       }
      }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult')
    xmlhttp.send()
    return false
    }
    </script>
    <form action="add.1" method="get" onsubmit="return calc()">
    <input type=text name=a value="<%=a%>"> + <input type=text name=b value="<%=b%>">
    = <input type=text name=total value="<%=total%>">
    <input type=submit value="Calculate">
    </form>
    <%
    }
    %>

    7、Using JSON as the transfer language

    xmlhttp.open("GET","/routeplanner/airport.1?LHR",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       if (xmlhttp.status!=404) {
        var local=new Function("return "+xmlhttp.responseText)();
        alert("Code - Name\n"+local[0].id+' - '+local[0].name);
       } else {
        alert("Airport not found");
       }
      }
    }
    xmlhttp.send(null);

    8、Using XMLHTTP with GOOGLE's SOAP API

    search="Word"
    xmlhttp.open("POST", "http://api.google.com/search/beta2",true);
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
       alert(xmlhttp.responseText)
      }
    }
    xmlhttp.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1")
    xmlhttp.setRequestHeader("MessageType", "CALL")
    xmlhttp.setRequestHeader("Content-Type", "text/xml")

    xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+"<SOAP-ENV:Envelope"+
          ' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
          ' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"'+
          ' xmlns:xsd="http://www.w3.org/1999/XMLSchema">'+
          '<SOAP-ENV:Body><ns1:doGoogleSearch'+
          ' xmlns:ns1="urn:GoogleSearch"'+
          ' SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
          '<key xsi:type="xsd:string">GOOGLEKEY</key> <q'+
          ' xsi:type="xsd:string">'+search+'</q> <start'+
          ' xsi:type="xsd:int">0</start> <maxResults'+
          ' xsi:type="xsd:int">10</maxResults> <filter'+
          ' xsi:type="xsd:boolean">true</filter> <restrict'+
          ' xsi:type="xsd:string"></restrict> <safeSearch'+
          ' xsi:type="xsd:boolean">false</safeSearch> <lr'+
          ' xsi:type="xsd:string"></lr> <ie'+
          ' xsi:type="xsd:string">latin1</ie> <oe'+
          ' xsi:type="xsd:string">latin1</oe>'+
          '</ns1:doGoogleSearch>'+
        '</SOAP-ENV:Body></SOAP-ENV:Envelope>')

    ================================================
    全文:http://www.jibbering.com/2002/4/httprequest.html


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    没人帮忙,那就靠自己,自己才是最好的老师!本人拒绝回答通过站内短消息提出的问题!

    blog:http://Qr.blogger.org.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/1/16 8:57:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/28 7:01:26

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    46.875ms