ajax php 聊天室实例代码(5)
发布:smiling 来源: PHP粉丝网 添加日期:2013-12-16 16:48:35 浏览: 评论:0
- function addonline(name)
- {
- if ($(name)) return;
- var d1 = document.createelement("div");
- d1.id = name;
- d1.innerhtml = name;
- d1.classname = "online";
- $('div_online').appendchild(d1);
- }
- touchme();
- function check_send(e)
- {
- if (!e) e = window.event;
- var obj = $('chat_word');
- if (isie) obj.style.height = obj.scrollheight+3;
- if (e.keycode == 13)
- {
- if ((!e.shiftkey && !e.altkey && !e.ctrlkey) || !isie)
- {
- chat_send();
- obj.style.height = 20;
- return false;
- }
- else if (isie) obj.style.height = obj.scrollheight+18;
- }
- return true;
- }
- var send_ajax;
- send_ajax_change = function()
- {
- if (send_ajax.readystate == 4)
- {
- if (send_ajax.status != 200)
- {
- send_ajax_error();
- return;
- }
- if (debug) alert("send_ajax response:"+send_ajax.responsetext);
- if (send_ajax.responsetext.indexof("name")!=-1)
- {
- alert('已经有人使用你的昵称了');
- $('chat_user').value = "";
- $('chat_user').focus();
- }
- else if (send_ajax.responsetext.indexof("repeat")!=-1)
- {
- $('chat_word').value = window.lastcontent;
- }
- on_send_ok();
- if (!window.loading)
- {
- window.dotouch = true;
- load_word();
- }
- $('chat_word').disabled = false;
- $('chat_word').focus();
- }
- }
- function on_send_begin()
- {
- with($('chat_word'))
- {
- disabled = true;
- style.backgroundcolor = "#eeeeee";
- }
- window.sending = 1;
- }
- function on_send_ok()
- {
- window.sending = 0;
- with($('chat_word'))
- {
- value = '';
- disabled = false;
- focus();
- style.backgroundcolor = "#ffffff";
- }
- }
- function on_send_error()
- {
- window.sending = 0;
- with($('chat_word'))
- {
- disabled = false;
- focus();
- style.backgroundcolor = "#ffffff";
- }
- }
- function send_ajax_error()
- {
- alert('error 103nwhen send wordsnnyou can send them again!');
- $('chat_word').value = window.lastcontent;
- window.sending = 0;
- on_send_error();
- }
- function chat_send()
- {
- send_ajax = createajax();
- send_ajax.open('post','<?php echo basename(__file__);?>',true);
- send_ajax.setrequestheader("content-type", "application/x-www-form-urlencoded");
- send_ajax.onreadystatechange = send_ajax_change;
- var urlstring = '';
- var name = $('chat_user').value.replace("n","");
- var content = $('chat_word').value;
- var bold = ($('input_bold').checked)?"bold":"";
- var size = parseint($('input_size').value);
- var font = $('input_font').value;
- if (name == "")
- {
- alert('please enter your nick name first!!');
- $('chat_user').focus();
- return;
- }
- if (content == "" || content == "n" || content == "nn" || content == "nnn")
- {
- alert('please enter your words!');
- $('chat_word').focus();
- $('chat_word').value = "";
- return;
- }
- if (size>100) size = 100;
- else if (size<0) size = 1;
- urlstring+= "action=write";
- urlstring+= "&name="+encode(name);
- urlstring+= "&content="+encode(content);
- urlstring+= "&bold="+bold;
- urlstring+= "&color="+window.color;
- urlstring+= "&size="+size;
- urlstring+= "&font="+font;
- urlstring+= "&room="+room;
- window.sending = 1;
- window.lastcontent = content;
- on_send_begin();
- if (debug) alert("sending:"+urlstring);
- send_ajax.send(urlstring);
- settimeout("if (window.sending) send_ajax.abort(); on_send_error();",5000);
- setcookie("chatusername",$('chat_user').value);
- }
- function resize(s)
- {
- var o = $('div_contents').style;
- var h = parseint(o.height);
- h = (s)?h+50:h-50;
- if (h<=50 || h>=3000) return;
- o.height = h;
- $('div_contents').scrolltop = 655350;
- }
- function clearall()
- {
- $('div_contents').innerhtml = "";
- }
- </script>
- </center>
- </body>
- </html>
- <?php
- }
- ?>
Tags: ajax 聊天室 实例
- 上一篇:ajax php 聊天室实例代码(4)
- 下一篇:php登录代码
相关文章
- ·ajax php 聊天室实例代码(1)(2013-12-16)
- ·ajax php 聊天室实例代码(2)(2013-12-16)
- ·ajax php 聊天室实例代码(3)(2013-12-16)
- ·ajax php 聊天室实例代码(4)(2013-12-16)
- ·PHP ajax 统计当前在线用户数程序代码(2014-01-06)
- ·php ajax用户登录代码(2014-01-15)
- ·php ajax用户登陆验证程序代码(2014-01-16)
- ·php+ajax实现无刷新的新闻留言系统(2014-02-10)
- ·php jquery ajax用户登录实例代码(2014-07-04)
- ·php+jquery ajax邮箱地址无刷新验证实例(2014-07-04)
- ·ajax+php无刷新回贴和注册检验实例(2014-07-05)
- ·php ajax 留言板(2014-09-09)
- ·php+ajax注册验证实例(完整代码)(2015-04-10)
- ·PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程(2021-04-09)
- ·PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程(2021-04-09)
- ·PHP+jQuery+Ajax实现用户登录与退出(2021-05-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)