我有四个选项,分别是 addQuestions.php 中具有值 1-4 的单、多、矩阵和真假问题。现在我已经使用 get 方法使用 ajax 通过 id 请求一个页面,并且在该请求的页面中我给出了一个条件如果 id ==1 那么它将包含一个文件是 singleQuestion.php 等等。现在出现的问题是在 singleQuestion.php 中,有四个带有单选按钮的选项。因此,当 ajax 请求该文件时,它会显示 singleQuestion.php 的所有内容,因此每当我提交位于 addQuestions.php 中的表单时,它就不会检索 singleQuestion.php 输入的值。以下是我的代码:- addQuestions.php
<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">
`
获取问题.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>
插入问题.php
<?php
echo $Answer1 = $_POST['Answer1'];
echo $Answer2 = $_POST['Answer2'];
?>
以上是我的代码,我是 ajax 的新手,所以我对 ajax 不太了解,这就是我被卡住的原因。任何帮助将不胜感激