我將在PHP中使用AJAX獲取選中的單選按鈕值。我已經完成了下面的代碼,但是我無法繼續。如何使用PHP中的AJAX獲取選中的單選按鈕值?
我需要你的幫助。
ajax_radio.php
<html>
<head>
<script type="text/javascript" src="ajax.js" ></script>
</head>
<body>
<input type="radio" name="radio1">Blue</input>
<input type="radio" name="radio2">White</input>
<input type="radio" name="radio3">Red</input>
<input type="button" name="btn" value="Click" onClick="hello('a')"></input><br />
<input type="text" id="btn_get" name="get_btn_value"></input>
</body>
</html>
ajax.js
var xmlHttp;
function GetXmlHttpObject(){
try{
xmlHttp = new XMLHttpRequest();
}
catch(e){
try{
xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);
}
catch(e){
try{
xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);
}
catch(e){
alert("doesn't support AJAX");
return false;
}
}
}
}
function hello(a){
GetXmlHttpObject();
xmlHttp.open("GET","ajax_radio.html?",true);
xmlHttp.onreadystatechange = response;
xmlHttp.send(null);
}
function response(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var radio_text = xmlHttp.responseText;
document.getElementById('btn_get').innerHTML = radio_text;
}
}
}
你知道如何完成呢?提前致謝。 :)
編輯:
我不能在這裏發佈的代碼,現在,由於網絡的低速。對不起。
我已在rapidshare中分享。你能先下載它,然後幫忙嗎?非常感謝。
當我回家時,我必須更新它。太糟糕了。
huuuuh,因此您無法粘貼代碼,因爲我們的網絡很慢?我認爲粘貼是一個標準的Windows功能:D ... – Younes 2010-01-27 10:20:24
我可以粘貼代碼,但是當我提交頁面時,它變成空白。我嘗試發佈其他地方或製作一個zip文件。我很抱歉。 – 2010-01-27 10:22:33
只需粘貼你的ajax的源代碼包裝它
– DoctorLouie 2010-01-27 10:32:14