无法加载资源:服务器响应状态为404 Not Found

问题描述 投票:0回答:3

我是Wordpress和Ajax的新手,并不知道如何解决这个问题,所以任何帮助都会受到赞赏。

我正在使用Wordpress主题,数据库中的所有学生都显示在表格中:

    <?php

get_header();

if(have_posts()):
    while(have_posts()) : the_post(); ?>

<article class="post page">
<a href="<?php the_permalink(); ?>"><?php the_content(); ?>

<!DOCTYPE html>
<html>
<head> 



        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  

<style>

}
    img {
    vertical-align: middle; 

}
    table {
    border-collapse: collapse;
    width: 100%;
    border-spacing: 50px 0;
    text-align: center;
}


    .hover:hover{
        background-color: antiquewhite;

    }
    td{
        padding: 10px;
    }
    .aligncenter{
        text-align: center;
    }


    div.scroll {
    position: static;
    width: 700px;
    height: 400px;
    overflow: scroll;
    overflow-x: hidden;
    }
    a {
    text-decoration: none;
    }


</style>
</head>

<body>
    <div class="scroll"><a href="<?php the_permalink(); ?>"><?php the_content(); ?> </a>
<?php
$mysqli = NEW MySQLi('localhost','root','','wp_db');

        if(isset($_GET['order'])){
            $order = $_GET['order'];
        }else{
            $order = 'name';
        }

        if(isset($_GET['sort'])){
            $sort = $_GET['sort'];
        }else{
            $sort ='ASC';
        }

        $result = $mysqli->query("SELECT * FROM wp_absolventen ORDER BY $order $sort");

        $image = $row['bild'];

        if($result->num_rows > 0){

            $sort == 'DESC' ? $sort = 'ASC' : $sort ='DESC'; // short IF statements 
                 ?>
                 <div class="table-responsive" style=overflow-x:auto;>  
            <table class="table table-bordered">
            <?php
            echo "
            <th></th>
            <th class='aligncenter'>
            <a href='?order=name&&sort=$sort'>Name</a></th>
            <th class='aligncenter'><a href='?order=geburtsdatum&&sort=$sort'>Geburtsdatum</a></a></th>
            <th class='aligncenter'><a href='?order=stadt&&sort=$sort'>Wohnort</a></th>
            ";
            ?>
            <?php
            while($rows = $result->fetch_assoc())
            {
                $name = $rows['name'];
                $geburtsdatum= $rows['geburtsdatum'];
                $stadt = $rows['stadt'];
                $p='<img src="data:image/jpg;base64,' . base64_encode( $rows['bild'] ) . '"/>';
                $id = $rows['id'];

                ?>

                <tr class='hover'>


                <td> <?php echo $p; ?></td>



                <td><input type="button" name="view" value="<?php echo $name; ?>" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" /></td> 



                <td><?php echo $geburtsdatum; ?></td>



                <td><?php echo $stadt; ?></td>
                </tr>

               <?php

            }

        }else{
            echo "No records returned.";
        }
        ?> 
        </table>
         </div>


</body>
</html>
</article>
  <div id="dataModal" class="modal fade">  
      <div class="modal-dialog">  
           <div class="modal-content">  
                <div class="modal-header">  
                     <button type="button" class="close" data-dismiss="modal">&times;</button>  
                     <h4 class="modal-title">Employee Details</h4>  
                </div>  
                <div class="modal-body" id="employee_detail">  
                </div>  
                <div class="modal-footer">  
                     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
                </div>  
           </div>  
      </div>  
 </div>  
    <script>  
 $(document).ready(function(){  
      $('.view_data').click(function(){  
           var employee_id = $(this).attr("id");  
           $.ajax({  
                url:"select.php",  
                method:"post",  
                data:{employee_id:employee_id},
                succes:function(data){  
                    $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  
      });  
 });  

 </script>










<?php 
    endwhile;

    else :
        echo '<p>No contect found</p>';
    endif;

get_footer();
?>

到目前为止一切都很好,但是当你点击一个学生名字时,它应该打开一个bootstrap模式,显示有关学生的信息(从数据库中获取)。

     <script>  
 $(document).ready(function(){  
      $('.view_data').click(function(){  
           var employee_id = $(this).attr("id");  
           $.ajax({  
                url:"select.php",  
                method:"post",  
                data:{employee_id:employee_id},
                succes:function(data){  
                    $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  
      });  
 });  

 </script>

这是调用另一个php文件(select.php)的函数,打开模态并从数据库中获取信息。 select.php文件:

<?php  
 if(isset($_POST["employee_id"]))  
 {  
      $output = '';  
      $connect = mysqli_connect("localhost", "root", "", "wp_db");  
      $query = "SELECT * FROM wp_absolventen WHERE id = '".$_POST["employee_id"]."'";  
      $result = mysqli_query($connect, $query);  
      $output .= '  
      <div class="table-responsive">  
           <table class="table table-bordered">';  
      while($row = mysqli_fetch_array($result))  
      {  
           $output .= '  
                <tr>  
                     <td width="30%"><label>Name</label></td>  
                     <td width="70%">'.$row["name"].'</td>  
                </tr>  

                ';  
      }  
      $output .= "</table></div>";  
      echo $output;  
 }  
 ?>

但是,当我尝试点击学生姓名时,模态没有打开,而是我得到这个404错误:无法加载资源:服务器响应状态http://localhost/wordpress/sample-page/select.php为404(未找到)。两个文件都在同一个文件夹中。

代码在不在wordpress文件夹中时有效。

M.M.

php jquery ajax wordpress wordpress-theming
3个回答
0
投票

我从另一个线程回答了类似的问题...基本上,建立/编写一个简单的php文件,如果你可以通过浏览器直接访问它,那么你通过ajax调用它....设置是在文件名前加上页面 - “title-of-page”.php,然后使用类似于上述约定的“title-of-page”创建一个空白页面,然后设置永久链接URL。这是另一个thread


0
投票

尝试使用数据属性发送文件路径,使其低于行

<td><input type="button" name="view" value="<?php echo $name; ?>" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" /></td>

<td><input type="button" name="view" value="<?php echo $name; ?>" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" data-file="<?php echo get_template_directory() . '/select.php'; ?>" /></td>

在线下,

url:"select.php",

url: $(this).data('file'),

我没有在我身边测试过。但这只是你的代码方式的一个想法。 编辑:

<td><input type="button" name="view" value="<?php echo $name; ?>" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" /></td>

<td><input type="button" name="view" value="<?php echo $name; ?>" id="<?php echo $row["id"]; ?>" class="btn btn-info btn-xs view_data" data-file="<?php echo get_template_directory_uri() . '/select.php'; ?>" /></td>

在线下,

url:"select.php",

url: $(this).data('file'),

0
投票

将php文件保存为page-select.php并在Wordpress页面中创建一个名为“select”的空白页面就可以了!虽然不是网址:“/ select”我只使用“选择”而且它有效!再次感谢您的安东尼和蒂鲁玛尼guhan!:)

© www.soinside.com 2019 - 2024. All rights reserved.