我有四個選項,分別是addQuestions.php中的單個,多個,矩陣和true值。現在我通過使用Ajax使用get方法請求一個頁面,並在該請求的頁面我已經給出了一個條件,如果id == 1,那麼它將包括一個文件是singleQuestion.php等等。現在的問題已經出現在singleQuestion.php中的單選按鈕有四個選項。所以,當ajax請求文件,然後它顯示singleQuestion.php的所有內容,所以無論何時我提交一個在addQuestions.php中的表單,然後它不檢索singleQuestion.php輸入的值。下面是我的代碼: - addQuestions.php當從ajax請求一個頁面並提交請求頁面的表單時,什麼都不顯示['Solved']
<form action="insertQuestion.php" method="post">
<select name="selectQuestionType" class="questionInput" onchange='showUser(this.value)' id="selectQuestionType">
<option value="0" selected>Select Question Type</option>
<option value="1">Single Choice </option>
<option value="2">Multiple Choice Question</option>
<option value="3">Fill in the Blanks</option>
<option value="4">True False</option>
<option value="5">Match Matrix</option>
</select>
<input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" name="myAddSave">
<input type="submit" class="button add" value="Save & Next" style="width:auto;" id="saveNext" name="myNextSave">
<script type="text/javascript">
`
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getQuestions.php?q="+str,false);
xmlhttp.send();
}
</script>
<div id="txtHint"><b>Question Mode will Be displayed here!.</b></div>
<input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" name="myAddSave">
<input type="submit" class="button add" value="Save & Next" style="width:auto;" id="saveNext" name="myNextSave">
`
getQuestions.php
<?php
$q=$_GET["q"];
if($q==1)
{
include 'singleQuestion.php';
}
else if($q == 2)
{
include 'multipleQuestion.php';
}
else if($q == 3)
{
include 'fillQuestion.php';
}
else if($q == 4)
{
include 'trueQuestion.php';
}
else if($q == 5)
{
include 'matchQuestion.php';
}
else
{
echo 'You Have Not Selected Any Question Type Yet!';
}
?>
在singleQuestion.php
<style type="text/css"> .javascript { display: none; } </style>
<?php
echo $Answer1 = $_POST['Answer1'];
echo $Answer2 = $_POST['Answer2'];
?>
<br>
<div class="singleContainer">
<div class="jdRadio">
<div class="jdRaOne">
<span class="Answer">A</span><br><br>
<span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide1" class="jdText">
<input type="text" name="Answer1" style="width:600px;padding:7px;" >
</div> </div>
<br><br><div class="jdRadio">
<div class="jdRaOne">
<span class="Answer">B</span><br><br>
<span class="jdAnswer"><input type="radio" name="A1" ></span>
</div>
<div id="Hide2" class="jdText">
<input type="text" name="Answer2" style="width:600px;padding:7px;" value="joydseep" >
</div> </div>
<br><br><div class="jdRadio">
<div class="jdRaOne">
<span class="Answer">C</span><br><br>
<span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide3" class="jdText">
<input type="text" name="Answer3" style="width:600px;padding:7px;" >
</div> </div>
<br><br><div class="jdRadio">
<div class="jdRaOne">
<span class="Answer">D</span><br><br>
<span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide4" class="jdText">
<input type="text" name="Answer4" style="width:600px;padding:7px;" >
</div> </div>
<div id='TextBoxesGroup'>
<div id="TextBoxDiv1">
<label style="color:#F1F1F1;">Textbox #1 : </label>
</div>
</div>
<br>
<div class="javascript">your script data to be executed. </div>
<input type="submit" name="jdb">
</form>
</div>
insertQuestion.php
<?php
echo $Answer1 = $_POST['Answer1'];
echo $Answer2 = $_POST['Answer2'];
?>
以上是我的代碼,我在阿賈克斯一個新手的東西,所以我不知道很多關於Ajax,這就是爲什麼我得到stucked.Any幫助將不勝感激多
''你都張貼有輸入RADIL – 2013-04-20 10:09:30
沒有價值,我建議嘗試jQuery的我nstead的飛機javascript – underscore 2013-04-20 10:10:07
我想發佈的文本框的答案是答案6 – user2296650 2013-04-20 10:12:25