问题是,我正在用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的头球,我想你们能帮上忙,我会非常感激的。
暂无答案!
目前还没有任何答案,快来回答吧!