首页 > 解决方案 > 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>

标签: ajaxwordpressurl

解决方案


推荐阅读