我正在制作这样的聊天程序:http ://www.webengine.co.kr/wechat?l= en(韩国网站),我遇到了标题之类的问题。(这个问题有时会出现,如果你想测试这个,请多次刷新页面。)
我认为这个问题是由我的 ajax 脚本造成的
function wechat(id, chatroom_srl, last_chatline_srl, key, nick_name){
this.id = id;
this.chatroom_srl = chatroom_srl;
this.last_chatline_srl = last_chatline_srl;
this.key = key;
this.nick_name = nick_name;
this.wechat = $("#"+this.id);
var oWechat = this.wechat;
function exec_json_nomsg(a,b,c){
if("undefined" == typeof b) b = {};
a = a.split(".");
if(2 == a.length){
$.extend(b, {module:a[0],act:a[1]});
if("undefined" != typeof xeVid) $.extend(b, {vid:xeVid});
$.ajax({
type:"POST",
dataType:"json",
url:request_uri,
contentType:"application/json",
data:$.param(b),
success:function(a){
if($.isFunction(c)) c(a);
}
});
}
}
function procChatLines(data){
for(i=0;i<data.chatline_list.length;i++){
appendLine(data.chatline_list[i].nick_name, data.chatline_list[i].content, data.chatline_list[i].key);
wechat.last_chatline_srl = data.chatline_list[i].chatline_srl;
}
wechat.timer = setTimeout(loadChatContents, 100);
}
function loadChatContents(){
exec_json_nomsg("chat.loadChatContents", {chatroom_srl:wechat.chatroom_srl, last_chatline_srl:wechat.last_chatline_srl, key:wechat.key}, procChatLines);
clearTimeout(wechat.timer);
}
function appendLine(nick_name, content, key){
var lineObj = $("<div class=\"chatLine\"></div>");
if(wechat.key == key) lineObj.addClass("chatMe");
lineObj.html("<span class=\"chatNickBold\">"+nick_name+" : </span>"+content);
oWechat.find(".chatContentHeight").append(lineObj);
scrollDown();
}
function scrollDown(){
var o = oWechat.find(".chatContent");
o.stop().animate({scrollTop:o.find(">.chatContentHeight").height()-o.height()}, 300, "easeInOutQuart");
}
$(window).load(function(){
scrollDown();
});
oWechat.find(".wechatInput").keydown(function(e){
if(e.keyCode == 13){
if($(this).val().trim() != ""){
exec_json_nomsg("chat.procChatInsertChatLine",{"chatroom_srl":wechat.chatroom_srl,"content":$(this).val()});
appendLine(wechat.nick_name, $(this).val(), wechat.key);
$(this).val("");
}
}
});
wechat.timer = setTimeout(loadChatContents, 100);
}
new wechat("wechat1", 1, [last_chatline_srl(PHP give this)], "[User Hidden Key(PHP give this)]", "[User Nick Name]");
我能做些什么来解决这个问题?