如例:index.html 
<script src="js_admin.js"> </script> 
<INPUT onchange="javascript:film_nametest()" name=t1> ccc.php <script src="js_admin.js"> </script> 
<?php 
switch ($act) { 
case "on": 
echo " <div id=responseT>我爱您中国$act </div>"; 
break; 

?> 
js_admin.js 
function film_nametest(){ 
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    xmlhttp.open("POST","http://127.0.0.1/ccc.php?act=on",true); 
    xmlhttp.send(); 
function doHttpReadyStateChange() {  
      if (xmlhttp.readyState == 4) alert(xmlhttp.responseTEXT);  
        }  
alert(innerHTML=responseT.innerHTML) 
} 怎样在才能在index.html弹出ccc.php?act=on 文件中的"中国我爱你"

解决方案 »

  1.   

    var net = new Object(); //名字空间对象
    net.READY_STATE_UNINITIALIZED = 0;
    net.READY_STATE_LOADING = 1;
    net.READY_STATE_LOADED = 2;
    net.READY_STATE_INTERACTIVE = 3;
    net.READY_STATE_COMPLETE = 4;

    ///////////////////////////////////////////////////
    net.ContentLoader = function(url,onload,onerror,method,params,contentType)
    { //构造函数

    this.url = url;
    this.req = null;
    this.onload = onload;
    //alert(onload);
    this.onerror = (onerror) ? onerror : this.defaultError;
    //alert(url);
    this.loadXMLDoc(url,method,params,contentType);

    }
    net.ContentLoader.prototype = 
    {

    loadXMLDoc:function(url,method,params,contentType)//重新命名的initXMLHttpRequest函数
    {
    //alert("loadXMLDoc");
    if (!method)
    {
    method="GET";
    }
    if (!contentType && method=="POST")
    {
      contentType='application/x-www-form-urlencoded';
    }
    ///////////////////////重构过的LoadXML函数/////////////////////////////////////////
    if(window.XMLHttpRequest)
    {
    this.req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
    this.req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    ///////////////////////////////////////////////////////////////
    if(this.req)
    {
    try
    {
    var loader = this;
    this.req.onreadystatechange = function()
    {
    loader.onReadyState.call(loader);
    }
    ////////////////重构过的sendRequest函数///////////////////////////////////////////
    //alert(url);
    //alert(method);
    this.req.open(method,url,true);
     if(contentType)
     {
            this.req.setRequestHeader('Content-Type', contentType);
         }
    this.req.send(params);
    }catch(err)
    {
    this.onerror.call(this);
    }
    }

    },

    onReadyState:function()//重构过的回调函数
    {
    //alert("onReadyState");
    var req = this.req;
    var ready = req.readyState;
    if(ready == net.READY_STATE_COMPLETE)
    {
    var httpStatus = req.status;
    if(httpStatus == 200 || httpStatus == 0)
    {
    //alert("back to client");
    this.onload.call(this);

    }
    else
    {
    this.onerror.call(this);
    }
    }
    },

    defaultError:function()
    {
    alert("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
    }

    }存为ContentLoader.js
    引入后用
    //发送请求
    function sendMyReq()
    {
    var curdate = new Date();
    var url = "http://127.0.0.1/ccc.php?curtime=" + new Date().getTime();
    var params = "act=on";
    new net.ContentLoader(url, sendMyReq_CallBack, null,'POST',params);
    //实例化一个ContentLoader对象
    }
    //回调函数
    function sendMyReq_CallBack()
    {
       alert(this.req.responseText);
    }