繁体   English   中英

加载资源失败:服务器响应,状态为404 Not Found

[英]Failed to load resource: the server responded with a status of 404 Not Found

我是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();
?>

到目前为止一切顺利,但是当您单击学生姓名时,它应该打开一个引导程序模版,其中显示有关学生的信息(从数据库中获取)。

     <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文件夹中时有效。

MM

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

尝试使用data属性发送文件路径,如下所示

<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'),

将php文件另存为page-select.php并在Wordpress页面中创建一个名为“ select”的空白页面就可以了! 虽然我没有使用url:“ / select”,但只使用了“ select”,但是它起作用了! 再次感谢您的宝贵时间Anthony和Thirumani guhan!:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM