- JScript code
$("#send").click(function() { var msg = $("#msg").val(); var user; if($("#user").val()==""){ user="游客"; }else{ user = $("#user").val(); } $.ajax({ type : "post", url : "chat_add", data : { msg : msg, user : user }, dataType : "json", success : function(jsonStr) { var data = eval(jsonStr); $ .each( data, function(i, n) { msgchat += n.time + " " + n.user + ":" + "<br>" + " " + n.msg + "<br>"; }); document .getElementById('showMsg').innerHTML = msgchat; document .getElementById('showMsg').scrollTop = document .getElementById('showMsg').scrollHeight; } }); $("#msg").val("");//清空 });
- Java code
public String add() throws Exception { chat.setMsg(msg); chat.setUser(user); this.chatService.addMsg(chat); this.msglist=this.chatService.searchMsg(chat);//查询 outputJson(msglist); return null; }
------解决方案--------------------
$("#send"),你这个send类型不会是submit吧而且放到表单里面?这样会提交表单就会刷新了
- JScript code
$("#msg").val("");//清空 return false;///////////增加这句阻止表单提交