ajax无刷新 模拟腾讯微博发心情,这里无需连接数据库,发表的心情直接显示在它的下面 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ajax取得数据就在列表下面加一个div之类 <div>显示的位置没搞上? document.getElementById("search_result").innerHTML="<ul><li>正在加载,请稍候</li></ul>";类似这样 自己拼写 我是这样写的:<%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf8"><title>模拟微博发心情无刷新</title><style type="text/css">#body { margin-left: 500px; border: 1px solid greed;}#showContent { height: auto; weight: 100% border:1px solid greed;}</style><script type="text/javascript"> //自定义AJAX引擎 var http_request=false; //初始化XMLHttpRequest对象 //浏览器的UI就是通过该对象与Ajax引擎打交道 function initXMLHttpRequest(){ if(window.XMLHttpRequest){ //Mozilla浏览器 http_request=new XMLHttpRequest(); if(http_request.overrideMineType){ //防止某些版本的Mozilla浏览器处理没有Mine Type信息的 //内容出错. http_request.overrideMineType("text/xml"); } } else if(window.ActiveXObject){ //IE浏览器 try{ //IE6或更高版本 http_request=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ //IE5.x http_request=new ActiveXObject("Microsoft.XMLHTTP"); } } } function submitContent(){ //初始化XMLHttpRequest对象 initXMLHttpRequest(); var content=document.getElementById("content").innerHTML; alert(content); //设置回调函数 http_request.onreadystatechange=callBack; //使用AJAX引擎的核心对象发送请求 http_request.open("POST","ajaxNOrefresh/weibo.jsp",true); http_request.send(); } function callBack(){ //AJAX引擎在服务器端成功返回后自动调用该函数 //负责将服务器端返回的数据显示在客户的UI上 if(http_request.readyState==4){ //服务器端已经处理完成 if(http_request.status==200){ //服务器端处理成功 //var content=document.getElementById("content"); //alert(content); document.getElementById("showContent").innerHTML=http_request.responseText; }else{ alert("错了!"); } } }</script><body> <div id="body"> <div id="top"> <form action="" method="post"> <textarea rows="5" cols="50" id="content" name="content">来,说说你在做什么,想什么。</textarea> <br> <button type="submit" onclick="submitContent()">提交</button> </form> </div> <div id="showContent">dsfsdfsd</div> </div></body></html>下面的div内容显示不出来 在回调函数里面判断的时候不成功,如果直接在外面写document.getElementById("showContent").innerHTML=document.getElementById("content").innerHTML; 取得的值在下面的div里一闪而过就没有了 肯定是动态无刷新的效果。 。使用AJAX 使用层替换 例如document.getElementById("search_result").innerHTML="<ul><li>正在加载,请稍候</li></ul>";自己拼接字符串 应该就可以。 http_request.send();==>http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");http_request.send();试试 如何提高上传速度 怎么从list中读取到自己想要的数据 JSP与SQL2000的连接问题 请教按时间查询的sql语句 哪位高手给讲讲response.encodeURL("j_security_check") poi读取execl中的日期问题 急急急 都急出尿来了. 关于结果集错误 如下介绍Enterprise Bean 与 JavaBean 的不同时有两个地方不明白,请指教,谢谢! jsp中使用组合查询SQL还有前台应该怎么写 跪求高手解决!~!java解析xml文件问题~!~! http://localhost:8080/MyProject/index.jsp 弹出xdb 用户名,密码
<%@ page language="java" contentType="text/html; charset=utf8"
pageEncoding="utf8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>模拟微博发心情无刷新</title>
<style type="text/css">
#body {
margin-left: 500px;
border: 1px solid greed;
}#showContent {
height: auto;
weight: 100% border:1px solid greed;
}
</style><script type="text/javascript">
//自定义AJAX引擎
var http_request=false;
//初始化XMLHttpRequest对象
//浏览器的UI就是通过该对象与Ajax引擎打交道
function initXMLHttpRequest(){
if(window.XMLHttpRequest){
//Mozilla浏览器
http_request=new XMLHttpRequest();
if(http_request.overrideMineType){
//防止某些版本的Mozilla浏览器处理没有Mine Type信息的
//内容出错.
http_request.overrideMineType("text/xml");
}
}
else if(window.ActiveXObject){
//IE浏览器
try{
//IE6或更高版本
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
//IE5.x
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}
}
}
function submitContent(){
//初始化XMLHttpRequest对象
initXMLHttpRequest();
var content=document.getElementById("content").innerHTML;
alert(content);
//设置回调函数
http_request.onreadystatechange=callBack;
//使用AJAX引擎的核心对象发送请求
http_request.open("POST","ajaxNOrefresh/weibo.jsp",true);
http_request.send();
}
function callBack(){
//AJAX引擎在服务器端成功返回后自动调用该函数
//负责将服务器端返回的数据显示在客户的UI上
if(http_request.readyState==4){
//服务器端已经处理完成
if(http_request.status==200){
//服务器端处理成功
//var content=document.getElementById("content");
//alert(content);
document.getElementById("showContent").innerHTML=http_request.responseText;
}else{
alert("错了!");
}
}
}
</script>
<body>
<div id="body">
<div id="top">
<form action="" method="post">
<textarea rows="5" cols="50" id="content" name="content">来,说说你在做什么,想什么。</textarea>
<br>
<button type="submit" onclick="submitContent()">提交</button>
</form>
</div>
<div id="showContent">dsfsdfsd</div>
</div>
</body>
</html>下面的div内容显示不出来
自己拼接字符串 应该就可以。
==>
http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http_request.send();试试