求助:ajax获取并以post方式发送表单数据
you can add a data into this table
<script type=”text/javascript”>
function loadXMLDoc ()
{
var xmlhttp;
xmlhttp=new XMLHttpRequest ();
xmlhttp.open(“POST”,”insert.php”,true);
xmlhttp.setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”);
xmlhttp.send(“name&sex&birth”);
}
</script>
<body>
name:
sex:
birth:
以上是网页代码,求助如何获取表单中的数据并用xmlhttp.send发送给insert.php
新人初学,还请多多关照
——解决方案——————–
把你前台的页面换成下面的
you can add a data into this table
<script type=”text/javascript”>
function loadXMLDoc ()
{
var xmlhttp;
var name = document.getElementById(“name”).value;
var sex = document.getElementById(“sex”).value;
var birth = document.getElementById(“birth”).value;
xmlhttp=new XMLHttpRequest ();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.responseText)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open(“P
+本文来源gao!%daima.com搞$代*!码9网(
搞gaodaima代码OST”,”./insert.php”,true);
xmlhttp.setRequestHeader(‘content-type’,’application/x-www-form-urlencoded’);
xmlhttp.send(“name=”+name+”&sex=”+sex+”&birth=”+birth);
}
</script>
<body>
name:
sex:
birth:
转载请注明原文链接:ajax获取并以post方式发送表单数据
