求助:ajax获取并以post方式发送表单数据 本帖最后由 u012296415 于 2013-11-26 11:04:16 编辑 you can add a data into this table <br /> function loadXMLDoc ()<br /> {<br /> var xmlhttp;<br /> xmlhttp=new XMLHttpRequest ();<br /> xmlhttp.open("POST","insert.php",true);<br /> xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");<br /> xmlhttp.send("name&sex&birth");<br /> }<br /> name: sex: birth: submit 以上是网页代码,求助如何获取表单中的数据并用xmlhttp.send发送给insert.php 新人初学,还请多多关照 php ajax 分享到: ------解决方案--------------------把你前台的页面换成下面的 you can add a data into this table <br /> function loadXMLDoc ()<br /> {<br /> var xmlhttp;<br /> var name = document.getElementById("name").value;<br /> var sex = document.getElementById("sex").value;<br /> var birth = document.getElementById("birth").value;<br /> <br /> xmlhttp=new XMLHttpRequest ();<br /> xmlhttp.onreadystatechange = function()<br /> {<br /> if (xmlhttp.readyState == 4 && xmlhttp.responseText)<br /> {<br /> alert(xmlhttp.responseText);<br /> }<br /> }<br /> xmlhttp.open("POST","./insert.php",true);<br /> xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');<br /> xmlhttp.send("name="+name+"&sex="+sex+"&birth="+birth);<br /> }<br /> name: sex: birth: submit