收集的网上用的ajax之chat.js文件

2016-02-19 10:05 16 1 收藏

get新技能是需要付出行动的,即使看得再多也还是要动手试一试。今天图老师小编跟大家分享的是收集的网上用的ajax之chat.js文件,一起来学习了解下吧!

【 tulaoshi.com - Web开发 】

var xmlHttp = false;
var ichatstate ;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}


function sendmsg(){
            var msgbody = escape(document.getElementById("msgbody").value);
            var sendto = escape(document.getElementById("sendto").value);
            var SendData = "msgbody=" + msgbody +"&sendto=" + sendto;
            xmlHttp.open("POST","../ichat/sendmsg.asp",false);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttp.onreadystatechange = function sendok(){ if (xmlHttp.readyState == 4) { } }
            xmlHttp.send(SendData);
            document.getElementById("msgbody").value = "";    
            showmsg();
}


function hot_key() {

if (window.event.keyCode==13 && window.event.ctrlKey && document.getElementById("msgbody").value != ""){sendmsg();}

}



function exitchat(){
  var url = "../ichat/online.asp?action=exit&pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

function intochat(){
window.ionline.location.href="../ichat/online.asp?action=intochat";
showmsg();
}

function showonline(){
  var url = "../ichat/online.asp?action=showonline&pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

function showmsg(){
  var url = "../ichat/getmsg.asp?pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = reloadX;
  xmlHttp.send(null);
}

function reloadX() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("mymsg").innerHTML = response;
document.getElementById("mymsg").scrollTop=document.getElementById("mymsg").scrollHeight;
setTimeout("showmsg();",10000);
}
}


function saveset(){
            var mycolor = document.getElementById("mycolor").value;
            var msgtotal = document.getElementById("msgtotal").value;
            var mystate = document.getElementById("mystate").value;
            var allowmsg = document.getElementById("allowmsg").value;
            var closemsg;

if(document.getElementById("closemsg").checked){
closemsg = document.getElementById("closemsg").value;
}else{
closemsg = "off";
}
            var SendData = "mycolor=" + mycolor + "&msgtotal=" + msgtotal + "&mystate=" + mystate + "&allowmsg=" + allowmsg + "&closemsg=" + closemsg;
            xmlHttp.open("POST","../ichat/chatset.asp",false);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttp.onreadystatechange = function sendok(){ if (xmlHttp.readyState == 4) { 
alert('设定已经保存')
if(ichatstate=="open"){window.location.reload();}
} }
            xmlHttp.send(SendData);

            showmsg();
            document.getElementById('layer_ichatset').style.display='none';

   
}

function openichat(){
ichatstate="open"
}

function closeichat(){
ichatstate="close"
}

function showonlineuser(){
document.getElementById('layer_online').style.display='block';

  var url = "../ichat/showonline.asp?pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = reloadX2;
  xmlHttp.send(null);

}

function reloadX2() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("onlineuser").innerHTML = response;
}
}

function readset(){
  document.getElementById('layer_ichatset').style.display='block';

  var url = "../ichat/myset.asp?pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = showset;
  xmlHttp.send(null);

}

function showset() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("setplan").innerHTML = response;
}
}

function setsendto(username) {
if (username=="所有人"){
document.getElementById("sendto").value = '';
document.getElementById("talkwith").innerHTML = '所有成员';
}else{
document.getElementById("sendto").value = username;
document.getElementById("talkwith").innerHTML = username;
}
  var url = "../ichat/checkuser.asp?user="+ escape(username) + "&pid=" +Math.random();
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = showtips;
  xmlHttp.send(null);
}

function showtips() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("userstate").innerHTML = response;
}
}

function clearlog() {

if (window.confirm("您确定需要清除所有聊天记录吗?")==true)
{
var url = "../ichat/clearlog.asp?pid=" +Math.random();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

}


var ichatwinstate
ichatwinstate="max";

function min()
{
ichatwinstate = (ichatwinstate=="max")?"min":"max"

if (ichatwinstate=="min"){
document.getElementById('mbody').style.display='none';
document.getElementById('myichat').height= parseInt(document.getElementById('ichat_title').height);
document.getElementById('myichat').style.top = document.body.clientHeight - parseInt(document.getElementById("ichat_title").style.height) + document.body.scrollTop;
}else{
document.getElementById('mbody').style.display='block';
iresize();
}
}


function closeit(){
document.getElementById('myichat').style.display='none';
}


function iresize(){
if (ichatwinstate=="min"){
document.getElementById('myichat').style.top = document.body.clientHeight - parseInt(document.getElementById("ichat_title").style.height) + document.body.scrollTop - 1;
}else{
document.getElementById('myichat').style.top = document.body.clientHeight  + document.body.scrollTop - parseInt(document.getElementById("mbody").style.height) -85;
}
}



var ey=0,ex=0,lx=0,ly=0,canDrg=false,thiso=null;
var x, y,rw,rh;

function dargit(o,e) //主函数
{
    thiso = o;
    canDrg = true;
    if(!document.all)
    {
        lx = e.clientX; ly = e.clientY;
    }
    else
    {
        lx = event.x; ly = event.y;
    }
    if(document.all) thiso.setCapture();
    try{}
    catch(e){}     
    st(o);//置前或置后

}
document.onmousemove=function(e)
{
    if(!document.all){ x = e.clientX; y = e.clientY; }else{ x = event.x; y = event.y; }
        if(canDrg)
        {
            var ofsx = x - lx;
            thiso.style.left = parseInt(thiso.style.left) + ofsx;
            lx = x;
            var ofsy = y - ly;
            thiso.style.top = parseInt(thiso.style.top) + ofsy;
            ly = y;

            // 状态栏显示数据
            //window.status=thiso.style.left+"left:top"+thiso.style.top+" rh:rw"+rh+"+"+rw;
        }
}

document.onmouseup=function()
{
    canDrg=false;//拖拽变量设为false
    try{}
    catch(e){}
    if(document.all && thiso != null)
    {
        //ie下,将清捕获;
        thiso.releaseCapture();
        thiso = null;
    }
}


function st(o)
{

    var p = o.parentNode;
    if(p.lastChild != o)
    {
      p.appendChild(o);
    }
    if(rh=20 && rw=160)
    {
        canDrg=false;

        if(rw180)
        {
             //设置关闭区域;//如果不需要可以注释掉;
               //alert("关闭");
            p.removeChild(o)
            //removeChild(this);

         }
        else
        {    
            window.status=rw+"|"+rh;
            if(p.firstChild == o) return;
            p.insertBefore(o, p.firstChild);
        }
    }
}

来源:https://www.tulaoshi.com/n/20160219/1593296.html

延伸阅读
标签: Web开发
代码如下: var partnertop="";  var partnerdomain=escape(document.domain);  var partnerurl=escape(document.URL);  var partnerfoot="";  var partnerad_leave="";  var partnerad_search="";  switch (partnerdomain) {  case 'www.flashku.c...
标签: Web开发
在上一篇中作者给大家详细介绍了两个非常实用的 ASP 内建对象 Application 和 Session 的使用方法。由于这两者的 OnStart、OnEnd 事件的脚本都必须在 Global.asa 文件中声明 , 因此,本篇将给大家详细介绍 Global.asa 文件的使用方法。为使大家熟练掌握至今所学过的知识,本篇还将举出一个 ASP 的 Chat 程序,供各位参考。 最近很多朋友来信问...
标签: Web开发
作者:马健 邮箱:stronghorse@tom.com 主页:http://stronghorse.yeah.net 版本:1.01 初始发布日期:2005.08.29 最后更新日期:2005.09.28 目录 一、前言 二、从E书或网页中获取文件的一般步骤 三、从E书或网页中获取链接进来的css文件 四、从E书或网页中获取链接进来的js文件 五、从E书或网页中获取Flash文件 六、从E书或网页中获取背景音乐...
标签: Web开发
    最近做的一个项目中有需要使用Ajax的部分,正好不是很忙,所以自己写了一个简单的Ajax类,拿出来share一下: function BmAjaxObject() {  this.ajaxObj = this.getXmlHttpObject(); } BmAjaxObject.prototype.getXmlHttpObject = function() {  var _ajaxObj;  try  {   _ajaxObj = new Ac...
标签: Java JAVA基础
  <object id=DirectDraw classid="CLSID:369303C2-D7AC-11D0-89D5-00A0C90833E6" style="positiion:absolute;top:0;left:0;width:320;height:200" <param name="line0001" value="绘图指令1" <param name="line0002" value="绘图指令2" ... </object ...

经验教程

678

收藏

76
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部