我有四个选项,分别是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">
`
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的新手,所以我不太了解ajax,这就是我被困的原因。任何帮助都会受到赞赏
答案 0 :(得分:1)
根据
修改您的singleQuestion.php
<?php
if(isset($_POST['jdb'])){
echo $Answer1 = $_POST['Answer1'];
echo $Answer2 = $_POST['Answer2'];
}
else{
?>
<br>
<div class="singleContainer">
<form name="form1" action="" method="post">
<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>
<?php }?>
在您的代码中,您错过了表单