php ajax
<!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> <pstyle="cursor:">jlfds</p> <input type="button" name="txt" id="button" value="button"/></body></html>
页:
[1]