52,797
社区成员
发帖
与我相关
我的任务
分享
<form name="touzi" method="post">
<table>
<tr>
<td>客户类型</td>
<td><input type="radio" name="customer-type" value="个人客户" id="0"/><input type="radio" name="customer-type" value="机构客户" id="1"/></td>
</tr>
<tr>
<td>联系人</td>
<td><input type="text" id="username"/></td>
</tr>
<tr>
<td>联系电话</td>
<td><input type="text" id="mobile"/></td>
</tr>
<tr>
<td>E-mail</td>
<td><input type="text" id="email"/></td>
</tr>
<tr>
<td>联系地址</td>
<td><input type="text" id="address"/></td>
</tr>
<tr>
<td>邮编</td>
<td><input type="text" id="postcode"/></td>
</tr>
<tr>
<td>内容</td>
<td><textarea id="customer-content"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="tijiao" onclick="submitForm()"/></td>
</tr>
</table>
</form>
function submitForm(){
var xmlHttp = createXmlHttp();
if(!xmlHttp) {
alert("您的浏览器不支持AJAX!");
return 0;
}
var url = 'phpmail.php';
var postData = "";
postData = "username=" + document.getElementById('username').value;
postData += "t=" + Math.random();
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function() {
alert(xmlHttp.status);
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if(xmlHttp.responseText == '1') {
alert('post successed');
}
}
}
xmlHttp.send(postData);
}
function createXmlHttp() {
var xmlHttp = null;
try {
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
//IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
<?php
if(isset($_POST['username']) {
echo '1';
}
?>