⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ajax.js

📁 c#网络聊天室源码c#网络聊天室源码c#网络聊天室源码
💻 JS
字号:
//5_1_a_s_p_x.c_o_m

var Simple=new Object();
Simple.Ajax=function(type,url,onload,params,contentType){
    this.req=null;
    this.url=url;
    this.params=params;
    if(type){
        this.type=type;
    }else{
        this.type="GET";
    }
    if(!contentType && type=="POST"){
        this.contentType="application/x-www-form-urlencoded; charset=UTF-8";
    }else{
        this.contentType=contentType;
    }
    this.onload=onload;
    this.responseText=null;
    this.GetHttpRequest();
}

Simple.Ajax.prototype.GetHttpRequest=function(){
    if(window.ActiveXObject){
        this.req=new ActiveXObject("Microsoft.XMLHTTP");
    }else if(window.XMLHttpRequest){
        this.req=new XMLHttpRequest();
    }
}

Simple.Ajax.prototype.SendRequest=function(){
    var loader=this;
    this.req.onreadystatechange=function(){
        loader.OnReadyState.call(loader);
    }
    this.req.open(this.type,this.url,true);
    if(this.contentType){
        this.req.setRequestHeader("Content-Type",this.contentType);
    }
    this.req.send(this.params);
}

Simple.Ajax.prototype.OnReadyState=function(){
    var ready=this.req.readyState;
    var data;
    if(ready==4){
        if(this.req.status==200 || this.req.status==0){
            this.responseText=this.req.responseText;
        }else{
            this.responseText="false";
        }
    }else{
        this.responseText="load";
    }
    this.onload.call(this,this);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -