ajax返回404,即使请求成功

enxuqcxy  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(309)

问题是,我正在用ajax请求更新数据库表中的几行,当我试图确保更新成功时,它返回一个404头,我转到网络工具,看到404,如下面的屏幕截图所示:

这是我为js和php编写的代码
PHP:

  1. <?php
  2. include("../../db_connect.php");
  3. if(isset($_POST['ads_left'])) {
  4. $ads_left = mysqli_real_escape_string($connect , $_POST['ads_left']);
  5. $ads_right = mysqli_real_escape_string($connect , $_POST['ads_right']);
  6. $ads_top = mysqli_real_escape_string($connect , $_POST['ads_top']);
  7. $ads_bottom = mysqli_real_escape_string($connect , $_POST['ads_bottom']);
  8. $ads_left = htmlentities($ads_left);
  9. $ads_right = htmlentities($ads_right);
  10. $ads_top = htmlentities($ads_top);
  11. $ads_bottom = htmlentities($ads_bottom);
  12. $ads_array = array();
  13. $ads_array[0] = $ads_top;
  14. $ads_array[1] = $ads_right;
  15. $ads_array[2] = $ads_bottom;
  16. $ads_array[3] = $ads_left;
  17. for ((int) $i = 0 ; $i<4 ; $i++) {
  18. $j = $i+1;
  19. $ins_ads_query = "UPDATE ads SET code = '$ads_array[$i]' WHERE id = '{$j}'";
  20. $result_ads = mysqli_query($connect , $ins_ads_query);
  21. }
  22. } else {
  23. header("Location: ../index.php");
  24. }
  25. ?>

js公司:

  1. var adsTop = document.getElementById('top');
  2. var adsRight = document.getElementById('right');
  3. var adsBottom = document.getElementById('bottom');
  4. var adsLeft = document.getElementById('left');
  5. var adsSubmit = document.getElementById("ads_submit");
  6. function updateAds(e) {
  7. e.preventDefault();
  8. adsSubmit.innerHTML = "Saving <i class=\"fa fa-circle-o-notch fa-spin\" style=\"font-size:24px\"></i>";
  9. var http = new XMLHttpRequest();
  10. var url = 'ajax/update_ads.php';
  11. var params = 'ads_top='+adsTop.value+'&ads_right='+adsRight.value+'&ads_bottom='+adsBottom.value+'&ads_left='+adsLeft.value;
  12. http.open('POST', url, true);
  13. //Send the proper header information along with the request
  14. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  15. http.send(params);
  16. http.onreadystatechange = function() {//Call a function when the state changes.
  17. if(http.readyState == 4 && http.status == 200) {
  18. adsSubmit.innerHTML = "Saved <span class=\"glyphicon glyphicon-floppy-saved\"></span>";
  19. }
  20. }
  21. }
  22. adsSubmit.addEventListener('click' , function(e) {
  23. updateAds(e);
  24. });

很奇怪,我真的不知道是什么引起了404的头球,我想你们能帮上忙,我会非常感激的。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题