此 ajax 函数获取一个文本框值并将其发送到"response.php"
:(这是的主要功能ajax.js
)
function ajaxFunction() {
var getdate = new Date();
if(xmlhttp) {
var txtname = document.getElementById("txtname");
xmlhttp.open("POST","response.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("txtname=" + txtname.value);
}
}
我正在尝试将一个单选按钮添加到我的表单中,所以我将其更改为:
function ajaxFunction() {
var getdate = new Date();
if(xmlhttp) {
var txtname = document.getElementById("txtname");
var radio = document.getElementById("radio2"); //ADDED
xmlhttp.open("POST","response.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("txtname=" + txtname.value);
xmlhttp.send("radio=" + radio.value); //ADDED
}
}
在 response.php 中:
<?php
if (isset($_POST['txtname'])){
$radio = $_POST['radio'];
//process...
}
?>
输入文本仍然有效,但单选按钮无效。