Ajax请求有效但不显示吗? [英] Ajax request working but not displaying?
问题描述
我对ajax请求有疑问.我创建了一个测验,它会询问所有问题,当用户完成测验时,它应调用AJAX.PHP文件的请求以调出信息.请在下面查看我的代码,我已经运行了ajax.php文件,它正在收集所有信息.但是在tests.php页面中,完成后什么也没显示.还有ajax $(#quiz_form,#demo1").addClass("hide");似乎没有任何显示,但没有完成下面的下两个功能.
有人可以帮忙吗?
AJAX请求-在tests.php中
我尝试过的事情:
I''m having an issue with an ajax request. I have a created a quiz which goes through questions and when the user finishes it, it should call a request to an AJAX.PHP file to call out information. Please see my code below, i have run the ajax.php file and it is gathering up all the information. But in the tests.php page, when it finishes it shows nothing. also the ajax $("#quiz_form,#demo1").addClass("hide"); seems to work as nothing displays, but doesnt complete the next two functions below.
Can someone help?
AJAX REQUEST - in tests.php
What I have tried:
function submit(){
$.ajax({
type: "POST",
url: "ajax.php",
data: $(''form'').serialize(),
success: function(msg) {
$("#quiz_form,#demo1").addClass("hide");
$(''#result'').show();
$(''#result'').append(msg);
}
});
ajax.php
ajax.php
$response= $db->prepare("SELECT id,question_name,answer FROM questions");
$response->execute();
$i=1;
$right_answer=0;
$wrong_answer=0;
$unanswered=0;
while($result=$response->fetch(PDO::FETCH_ASSOC)) {
// while($result=mysql_fetch_array($response)){
if($result[''answer'']==$_POST["$i"]){
$right_answer++;
}else if($_POST["$i"]==5){
$unanswered++;
}
else{
$wrong_answer++;
}
$i++;
}
echo "<div id=''answer''>";
echo " Right Answer : ". $right_answer."<br>";
echo " Wrong Answer : ". $wrong_answer."<br>";
echo " Unanswered Question : ". $unanswered."<br>";
echo "</div>";
推荐答案
(#quiz_form,#demo1").addClass("hide");似乎没有任何显示,但没有完成下面的下两个功能.
有人可以帮忙吗?
AJAX请求-在tests.php中
我尝试过的事情:
("#quiz_form,#demo1").addClass("hide"); seems to work as nothing displays, but doesnt complete the next two functions below.
Can someone help?
AJAX REQUEST - in tests.php
What I have tried:
function submit(){
.ajax({ 输入:"POST", 网址:"ajax.php", 数据:
.ajax({ type: "POST", url: "ajax.php", data:
(``form'').serialize(), 成功:function(msg){
(''form'').serialize(), success: function(msg) {
这篇关于Ajax请求有效但不显示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!