dongsheng4679 2013-06-26 15:43
浏览 25
已采纳

一旦没有更多的结果,jQuery Ajax

I'm building a simple quiz for a client that's getting it's data from their database and I'm loading the questions with a Ajax call to get the next question after they answer the first one. That is all functioning fine but the problem I've run into is what would be the best method to check if there are no more questions, currently I'm using success: to replace the content with the next question and error: to replace the content with the end of quiz screen. If anyone could give me some advice on a better method it would be very much appreciated as I don't really want to use error: as in case there's an actual error with the Ajax call it would just say the quiz is done when I would want the user to be able to try the action again, thanks in advance!

  • 写回答

1条回答 默认 最新

  • dsznndq4912405 2013-06-26 15:45
    关注
    complete: function(data){
      if(data.length !== 0){
        // change question
      }else{
        // completed quiz
      }
    }
    

    then in your PHP, just return an empty json object when there are no further questions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大