請問大大們,想利用AJAX做動態即時顯示,利用下面這篇教學延展!!!
https://dotblogs.com.tw/jhsiao/archive/2014/08/30/146411.aspx
這是改成radio單選選項,就不能顯示...不過get網址頁,是有顯示get變數...
是我程式哪邊需要改嗎?
AJAX首頁
<!DOCTYPE html>
<html>
<SCRIPT type="text/javascript">
var xmlhttp = false;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function serverconnect(divID, datalocation)
{
var1=$clickvalue;
if(xmlhttp)
{
var obj = document.getElementById(divID);
var disc = document.getElementById("select_op");
//xmlhttp.open("GET", datalocation + "?disc="+disc);
xmlHTTP.open("GET","6666.php?disc="+disc,true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 &&
xmlhttp.status == 200)
{
//obj.innerHTML = xmlhttp.responseText;
var str=xmlHTTP.responseText;
document.getElementById("message").innerHTML=str;
}
}
xmlhttp.send(null);
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="./ajax_select.js"></script>
<title>未面談確認清單(查詢)</title>
</head>
<body>
<font size="5"><strong>未面談確認清單(查詢)</strong></font>
<BR><BR>
<form name="form1" id="form1" onsubmit="serverconnect('Div1', '6666.php'); return false;">
<fieldset>
<legend>未面談確認清單</legend>
<p>請選擇:</p>
<p>
<label><input type="radio" name="select_op" id="select_op" value="10" checked /><!--checked--> 未面談確認(受評者)</label>
<label><input type="radio" name="select_op" id="select_op" value="20" /> 未面談確認(直屬主管)</label>
<label><input type="radio" name="select_op" id="select_op" value="1000" /> 兩者已面談確認</label>
<!--<input type="submit" value="搜尋" />-->
</p>
<p>
<div id='message'></div>
</p>
<BR>
</fieldset>
</form>
</body>
</html>
PHP頁面
<?php
$select_op=$_GET['select_op'];
if($select_op != "")
{
if($select_op == "10")
{
echo "未面談確認(受評者)";
}
else if($select_op == "20")
{
echo "未面談確認(直屬主管)";
}
else if($select_op == "1000")
{
echo "兩者已面談確認";
}
}
else
{
echo "請選擇一個選項";
}
?>
id 是不能重覆的…
感謝前輩回覆~
已經用以下方法取得到值,再利用前例的教學套用就OK了~
https://blog.csdn.net/magi1201/article/details/44465557