zoukankan      html  css  js  c++  java
  • 一段可以判断浏览器的ajax的js代码


    var objRequest;
    function SendValue(val)
    {
    //初始化
    try
    {//MS IE浏览器
    objRequest=new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e)
    {
    try
    {//所有的非IE浏览器
    objRequest=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(oc)
    {objRequest=null;}
    }
    if(!objRequest&&typeof XMLHttpRequest!="undefined")
    {objRequest=new XMLHttpRequest();}
    //处理请求的Web页面
    var url="http://localhost/VBNETSample/HandleAjaxRequests.aspx?sStringIn=" + val;
    if(objRequest!=null)
    { objRequest.onreadystatechange = Process;
    objRequest.open("GET", url, true);
    objRequest.send(null);
    }
    }
    function Process()
    {
    if (objRequest.readyState == 4)
    //值"4"意味着,我们现在可以使用XMLHttpRequest返回的数据
    { if (objRequest.status == 200)
    { document.getElementById("txtEchoOutPut").innerText = objRequest.responseText;
    //IE
    //document.getElementById("txtEchoOutPut").innerHTML = objRequest.responseText;
    //另外的浏览器
    }
    else
    { document.getElementById("txtEchoOutPut").innerHTML= "There was a problem retrieving
    data:<br>" + objRequest.statusText;}
    }
    }
    var objRequest;function SendValue(val){//初始化try{//MS IE浏览器objRequest=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{//所有的非IE浏览器objRequest=new ActiveXObject("Microsoft.XMLHTTP");}catch(oc){objRequest=null;}}if(!objRequest&&typeof XMLHttpRequest!="undefined"){objRequest=new XMLHttpRequest();}//处理请求的Web页面var url="http://localhost/VBNETSample/HandleAjaxRequests.aspx?sStringIn=" + val;if(objRequest!=null){ objRequest.onreadystatechange = Process;objRequest.open("GET", url, true);objRequest.send(null);}}function Process(){if (objRequest.readyState == 4)//值"4"意味着,我们现在可以使用XMLHttpRequest返回的数据{ if (objRequest.status == 200){ document.getElementById("txtEchoOutPut").innerText = objRequest.responseText;//IE//document.getElementById("txtEchoOutPut").innerHTML = objRequest.responseText;//另外的浏览器}else{ document.getElementById("txtEchoOutPut").innerHTML= "There was a problem retrievingdata:<br>" + objRequest.statusText;}}}
  • 相关阅读:
    运筹学 CheatSheet
    东南大学 2021 年夏季赛部分题解
    信号与系统期末复习精要
    信号量的基本同步模式
    OpenMP入门:求pi
    肉眼可见的 Z 变换性质
    操作系统概念 第7章 死锁
    操作系统概念 第10章 文件系统接口
    操作系统概念 第9章 虚拟内存
    操作系统概念 第8章 内存管理
  • 原文地址:https://www.cnblogs.com/chinatefl/p/1181849.html
Copyright © 2011-2022 走看看