php零基础入门
入口代码index.html 反ajax推送 .send{color:#555;text-align:left;}
.require{color:blue;text-资源网align:right;} .content_box{text-align:center;margin:20px; border:1pxsolid#ddd;padding:20px;}
消息框
1 资源网2
发送 连接
$(function(){ //发送消息
$(#btn_send).click(function(){ varsend_text=$(#send_text).val(); if(se资源网nd_text.length<=0){ $(#error_tip).html(不能输入空值);
}else{ send(send_text); } }); //按回车键发送消息 $(#sen资源网d_text).on(keyup,function(e){ if(e.keyCode==13){
$(#btn_send).trigger(click); } }); //建立通讯链接 $(#资源网btn_link).click(function(){ connect(); var_this=$(this);
_this.attr(disabled,true); _this.html(已连接资源网); }); }); //建立通讯连接函数 functionconnect(){ $(#content_box_title).html($(#username).val()+的消息窗口);
$资源网.ajax({ data:{user:$(#username).val()}, url:ajaxPush.php, type:get, timeout:0, dataType:json,
su资源网ccess:function(data){ $(#content_box).append(+data.msg+); connect(); }
}); } //发送消息函数 functions资源网end(massege){ varuser=$(#username).val(); $.getJSON(write.php,{msg:massege,user:user},function(dat资源网a){
if(data.sf){ $(#content_box).append(+massege+); $(#send_text).val(); }else{
$(#error_tip).html(资源网输入保存错误!); } }); } ajax处理输入write.php
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。