ajxser

<script>

   <span style="background-color: #c0c0c0;"> var xmlHttp;</span>//创建一个对象
    function queryDetail(id){
        if(window.ActiveXObject){
            xmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
        }else if(window.XMLHttpRequest){
            xmlHttp = new XMLHttpRequest();
        }
 
        if(!xmlHttp){
            alert("没有获取到对象!");
            return;
        }
 
<span style="background-color: #00ff00;">        //由于javascript是没有办法连接数据库的,所以,需要通过后台语言
        //结合来连接数据库,那么这里就是把js从界面获取的值,传递给后台程序
        //xmlHttp.open()其实也就是链接到一个后台程序,把值传递过去
        //这其实是第一步</span>
        xmlHttp<span style="background-color: #ff0000;">.open("GET","queryById.php?id="+id,true);</span>
 
<span style="background-color: #00ff00;">        //这是第三步
        //这一步是一个回调函数,回调函数其实就和打电话代办事情是一个意思
        //这个回调函数其实就是状态改变的时候,js应该做什么事情</span>
        xmlHttp<span style="background-color: #ff0000;">.onreadystatechange = function()</span>{
            if(xmlHttp.readyState == 4){
                if(xmlHttp.status == 200){
                    var txt = xmlHttp.responseText;
                    var show = document.getElementById("show")
                    if(show){
                        show.innerHTML = "";
                        document.body.removeChild(show);
                    }else{
                        var d = document.createElement("div");
                        d.id = "show";
                        d.style.cssText="width:200px;height:300px;border:1px solid red;";
                        var strs = txt.split(",");
                        alert(strs);
                        for(var i=0;i<strs.length;i++){
                            d.innerHTML += strs[i] + "<br/>";
                        }
 
 
                        document.body.appendChild(d);
                    }
 
 
                }
            }
        }
 
 
   <span style="background-color: #00ff00;">     //注意,open()方法就仅仅只是打开了连接,并没有传递,所以需要send方法
        //这是第二步</span>
        xmlHttp.<span style="background-color: #ff0000;">send(null);</span>
 
    }
 
 
 
 
</script>
posted @ 2014-05-09 20:16  三月迷离  阅读(122)  评论(0编辑  收藏  举报