PHP-为什么我的Ajax无法执行我的SQL查询?

前端之家收集整理的这篇文章主要介绍了PHP-为什么我的Ajax无法执行我的SQL查询? 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我一直在尝试找出为什么我的ajax调用SQL查询无法正常工作的原因.当我查看脚本时,找不到任何错误,我的请求页面如下所示:

  1. echo '<html><body>
  2. <div class="first-row" bordercolor="yellow">
  3. <div id="countdown"></div>
  4. <script>
  5. function UpdateRecord()
  6. {
  7. var userid = '.$userid.';
  8. $.ajax({
  9. type:"POST",url:"spotlightcount.PHP",data:{ userid: userid },success:function () {
  10. alert("Ok!");
  11. }
  12. });
  13. }
  14. </script>
  15. <script>
  16. var timeleft = 10;
  17. var downloadTimer = setInterval(function(){
  18. document.getElementById("countdown").innerHTML = timeleft + " seconds remaining";
  19. timeleft -= 1;
  20. if(timeleft <= 0){
  21. clearInterval(downloadTimer);
  22. document.getElementById("countdown").innerHTML = "Finished";
  23. UpdateRecord();
  24. }
  25. },1000);
  26. </script>
  27. </div>
  28. <div class="second-row">
  29. <iframe src="'.$row['adurl'].'"></iframe>
  30. </div>
  31. </body></html>';

然后spotlightcount.PHP具有以下内容

  1. include "config.PHP";
  2. MysqL_connect($dbhost,$dbuser,$dbpass);
  3. MysqL_select_db($dbname) or die("Error: Unable to select database");
  4. session_start();
  5. if (isset($_POST['userid'])){
  6. $userid = $_POST['userid'];
  7. @MysqL_query("Update ".$prefix."members set responsepoints=responsepoints+10,credits=credits+10 where Id=$userid limit 1") or die(MysqL_error());
  8. }
  9. exit;
  10. ?>

现在无论我做什么,当我加载页面时,完成10秒钟的倒计时,统计信息仍然不会更新..我找不到它的问题所在.

最佳答案
您正在使用jQuery函数($.ajax),但尚未导入该库.

关闭body标签之前添加

< script type =“ text / javascript” src =“ https://code.jquery.com/jquery-3.3.1.js”>< / script>

猜你在找的HTML相关文章