ajax - ajax 调用后发布 http://localhost/DemoWebsite/wp-admin/custom_Settings.php 404 (Not Found)
问题描述
当我的 ajax 调用同一页面时,我的服务器给我如下响应。在 Ajax 调用之前,控制台上的一切工作正常,但在 ajax 调用和更新数据库之后,发生此错误。我认为我的 Ajax_url 不正确,但我想在 url 中提到的名称为“custom_Settings.php”的同一页面上获取 ajax 数据。请帮我解决这个错误。谢谢!
jquery-3.4.1.min.js:2 POST http://localhost/DemoWebsite/wp-admin/custom_Settings.php 404(未找到)
JS
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){
saveNewPositions();
});
function saveNewPositions(){
var positions = [];
$j('.updated').each(function(){
positions.push([$j(this).attr('data-index'), $j(this).attr('data-position')]);
$j(this).removeClass('updated');
});
$j.ajax({
url: 'custom_Settings.php',
method: 'POST',
dataType: 'text',
data: {
update: 1,
positions: positions
}, success: function(response){
console.log(response);
}
});
}
</script>
PHP
function wp_pageOrdering_field_settings(){
global $wpdb;
if (isset($_POST['update'])) {
foreach($_POST['positions'] as $position){
$index = $position[0];
$newPosition = $position[1];
}
$wpdb->update(
'wp_page_settings',
array('page_order' => $newPosition),
array('ID' => $index)
);
wp_die();
}
HTML
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title></title>
</head>
<body>
<div class="container" style="margin-top: 100px;">
<div class="row justify-content-center">
<div class="col-md-4 col-md-offset-4">
<table class="table table-stripped table-hover table-border">
<head>
<tr>
<td>Page Title</td>
</tr>
</head>
<tbody>
<?php
$var = get_option('Accessable_Pages');
$list = implode(",", $var);
$newRes = $wpdb->get_results("SELECT ID, post_title, page_order FROM wp_page_settings WHERE ID IN ($list) ORDER BY page_order ASC",ARRAY_A);
if($newRes){
foreach ($newRes as $value1 ) {
echo '
<tr data-index="'.$value1['ID'].'" data-position="'.$value1['page_order'].'">
<td>'.$value1['post_title'].'</td>
</tr>
';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
解决方案
推荐阅读
- assembly - TLB 是否包含在内?
- excel - 从过滤表中获取可见数据
- python - Python-pptx - 将图片插入形状和动画
- java - 如何在Android parse.com Java中获取类的所有列名
- java - 当两个 logback.xml 在 Websphere 服务器上运行时,日志被合并
- javascript - 无法弄清楚为什么应用程序没有部署到heroku
- python - 熊猫数据框是从右到左?
- azure - Azure 管道未运行 - 属性参数为空
- python-3.x - 匀称的循环不创建线串
- ios - 在 macOS 10.13(或 iOS 12)及更早版本上将 WKWebView 的继承外观设置为 InterfaceStyle: .Dark