【发布时间】:2012-05-27 13:50:06
【问题描述】:
这个 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...
}
?>
输入文本仍然有效,但单选按钮无效。
【问题讨论】:
标签: php javascript ajax