dongtuo0828 2014-03-21 17:35
浏览 18
已采纳

我想在ajax电话下访问另一页

helllo i m making a quiz. i m fetching questions from database . while im using ajax to display the questions by refreshing a div tag. here is the code of ajax used.

  $(document).ready(function(){
 $("#button").click(function(){
 var q_id=$("#h_val").val();
 $("#rv").val(q_id);    
  $.ajax({ url: 'data.php',
            type: "POST",
            data: {"q_id":q_id} ,
            success: function(result) { 
            $('#que').html(result); 
            var newValue = parseInt(q_id) + 1

            $('#h_val').val(newValue); 

            } 



 });


});
});

now this is the data.php page code.

<?php



      $qid=$_POST['q_id'];
      $con = mysql_connect('localhost', 'root', '') or die(mysql_error());
            $db = mysql_select_db('quiz', $con) or die(mysql_error());
            $q="select * from question where qno=$qid";
            $rq=mysql_query($q,$con);
            if(!$rq)
            {
            echo " the sql query faiiled to work ";
            }
            else
            {
            if (mysql_num_rows($rq) == 0)
            {
            echo "database is empty.";
            }
            else
            {
            while ($sub_row=mysql_fetch_array($rq))
            {
            $id=$sub_row["qno"];
            $question=$sub_row["question"];
            $option1=$sub_row["option1"];
            $option2=$sub_row["option2"];
            $option3=$sub_row["option3"];
            $option4=$sub_row["option4"];



            echo "<h5>Q".$id." : ".$question."</br></h5>";   
            echo"</br><br>
             <h4><input type= radio id='1' name=\"{$id}\" value=\"{$option1}\">$option1</h4>
                </br>

                <h4><input type= radio id='2' name=\"{$id}\" value=\"{$option2}\">$option2</h4>
                </br>

                <h4><input type= radio id='3' name=\"{$id}\" value=\"{$option3}\">$option3</h4>
                </br>

                <h4><input type= radio id='4' name=\"{$id}\" value=\"{$option4}\">$option4</h4>
                </br></br>";
                }
                }
          }


                    ?>

i just want to go to a page when the question get over. while using header loaction whole page is coming in div . i just want a code to replace the line "databse is empty" which will redirect me to anther page .

  • 写回答

1条回答 默认 最新

  • dou70260 2014-03-21 17:43
    关注

    Should be done in js. As per your current code, try this

    success: function(result) { 
                if(result=="database is empty.") {
                  window.location="newurl.php";
                }
                $('#que').html(result); 
                var newValue = parseInt(q_id) + 1
    
                $('#h_val').val(newValue); 
    
                } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来