六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 30|回复: 0

php ajax

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-1-23 02:43:21 | 显示全部楼层 |阅读模式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- 以下是教你怎么结合php,xmlHttp和JS来传值以达到在同一个页面里操作数据的: --><html>  <head>    <title></title>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">    <script>        function getXmlHttpObject()        {            var xmlHttp=null;            //以下是四大浏览器            try{                // Firefox, Opera 8.0+, Safari                xmlHttp = new XMLHttpRequest();            }catch(e){                //Internet Explorer                try{                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");                }catch(e){                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");                }            }            return xmlHttp;        }        function clickbutton()        {            //根据ID获取一个input里面的值            var str = document.getElementById('txt').value;            //location.href = "php.php?txt="+test.value;            //取得一个XmlHttp对象            xmlHttp = getXmlHttpObject();            var url="php.php";            var poststr="q="+str;            //poststr=poststr+"&sid="+Math.random();            //用xmlHttp里的onreadystatechange方法得到准备好的状态            xmlHttp.onreadystatechange=stateChanged;            xmlHttp.open("POST",url,true);            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");            xmlHttp.send(poststr);                    }        function stateChanged()        {            if(xmlHttp.readyState==4)            {                var res = xmlHttp.responseText;                alert(res);                //document.getElementById("txtHint").innerHTML=xmlHttp.responseText;            }        }       </script>  </head>  <body>    <input type="text" name="txt" id="txt" />    <a href="">test</a>    <p  style="cursor:">jlfds</p>    <input type="button" name="txt" id="button" value="button"  />  </body></html> 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表