zoukankan      html  css  js  c++  java
  • 研究了下Ajax,写了个处理Ajax函数

    /**
     * CopyRight (c) Eays Studio
     * @author 小林信仁 Date:2007-2-11 QQ:16942926 Email:xihaikun@yahoo.com.cn
     */
    var http_request = false;

    function send_request(url){//初始化发送请求和处理函数
        http_request = false;
        //开始创建XMLHttpRequest对象
        if(window.XMLHttpRequest) {//Mozailla Navigation
            http_request = new XMLHttpRequest();
            if(http_request.overrideMimeType){//设置Mime类型
                http_request.overrideMimeType("text/html");
            }
        }else if(window.ActiveXObject){//IE Navigationg
            try{
            http_request = new ActiveXOjbect("Msxml2.XMLHTTP");
            }catch(e){
                try{
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e){}
            }
        }
        if(!http_request){//Exception 不能创建XMLHttpRequest对象
            window.alert("不能创建XMLHttpRequest实例");
            return false;
        }
        http_request.open("GET",url,true);
        http_request.send(null);
        http_request.onreadystatechange = processRequest;//onreadystatechange 是一个事件改变的触发器 等于号后面的是函数没有参数没有刮号,也可以是匿名函数http_request.onreadystatechange = function(){}
        
        //处理返回信息函数
    function processRequest(){
        if(http_request.readyState == 4 ) {
            if(http_request.status == 200){
                window.alert(http_request.responseText);//具体操作根据实际修改
            }else{
                alert("您所请求的页面有异常!!");
            }
        }
       }
    }
     
  • 相关阅读:
    相对路径与绝对路径问题
    javaee自定义servlet的步骤
    Struts1.X与Spring集成——另外一种方案
    菜鸟也能学cocos2dx3.0 浅析刀塔传奇(下)
    JAVA之了解类载入器Classloader
    IOS 编程中引用第三方的方类库的方法及常见问题
    通过eclipse的egit插件提交提示Auth fail
    定时器0的方式1 定时器1的方式1 数码管和led
    MongoDB入门学习(四):MongoDB的索引
    J2EE--JDBC
  • 原文地址:https://www.cnblogs.com/xhk1228/p/3172825.html
Copyright © 2011-2022 走看看