问题是我在ajax请求的数据库表中使用了几行代码。当我尝试确保更新成功时,它返回404标题,我转到网络工具和我看到404如下面的屏幕截图所示:
这是我对js和php
的代码PHP:
<?php
include("../../db_connect.php");
if(isset($_POST['ads_left'])) {
$ads_left = mysqli_real_escape_string($connect , $_POST['ads_left']);
$ads_right = mysqli_real_escape_string($connect , $_POST['ads_right']);
$ads_top = mysqli_real_escape_string($connect , $_POST['ads_top']);
$ads_bottom = mysqli_real_escape_string($connect , $_POST['ads_bottom']);
$ads_left = htmlentities($ads_left);
$ads_right = htmlentities($ads_right);
$ads_top = htmlentities($ads_top);
$ads_bottom = htmlentities($ads_bottom);
$ads_array = array();
$ads_array[0] = $ads_top;
$ads_array[1] = $ads_right;
$ads_array[2] = $ads_bottom;
$ads_array[3] = $ads_left;
for ((int) $i = 0 ; $i<4 ; $i++) {
$j = $i+1;
$ins_ads_query = "UPDATE ads SET code = '$ads_array[$i]' WHERE id = '{$j}'";
$result_ads = mysqli_query($connect , $ins_ads_query);
}
} else {
header("Location: ../index.php");
}
?>
JS:
var adsTop = document.getElementById('top');
var adsRight = document.getElementById('right');
var adsBottom = document.getElementById('bottom');
var adsLeft = document.getElementById('left');
var adsSubmit = document.getElementById("ads_submit");
function updateAds(e) {
e.preventDefault();
adsSubmit.innerHTML = "Saving <i class=\"fa fa-circle-o-notch fa-spin\" style=\"font-size:24px\"></i>";
var http = new XMLHttpRequest();
var url = 'ajax/update_ads.php';
var params = 'ads_top='+adsTop.value+'&ads_right='+adsRight.value+'&ads_bottom='+adsBottom.value+'&ads_left='+adsLeft.value;
http.open('POST', url, true);
//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.send(params);
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
adsSubmit.innerHTML = "Saved <span class=\"glyphicon glyphicon-floppy-saved\"></span>";
}
}
}
adsSubmit.addEventListener('click' , function(e) {
updateAds(e);
});
这很奇怪,我真的不知道是什么引起404标题,我们你们可以提供任何帮助,我会非常感激。