模拟腾讯微博发心情,这里无需连接数据库,发表的心情直接显示在它的下面

解决方案 »

  1.   

    ajax取得数据就在列表下面加一个div之类
      

  2.   

    <div>显示的位置没搞上?
      

  3.   

    document.getElementById("search_result").innerHTML="<ul><li>正在加载,请稍候</li></ul>";类似这样 自己拼写
      

  4.   

    我是这样写的:
    <%@ 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内容显示不出来
      

  5.   

    在回调函数里面判断的时候不成功,如果直接在外面写document.getElementById("showContent").innerHTML=document.getElementById("content").innerHTML; 取得的值在下面的div里一闪而过就没有了
      

  6.   

    肯定是动态无刷新的效果。 。使用AJAX 使用层替换 例如document.getElementById("search_result").innerHTML="<ul><li>正在加载,请稍候</li></ul>";
    自己拼接字符串 应该就可以。
      

  7.   

    http_request.send();
    ==>
    http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    http_request.send();试试