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 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口