阿贾克斯赢了';在.htaccess中对POST php的响应

阿贾克斯赢了';在.htaccess中对POST php的响应,php,jquery,mysql,ajax,.htaccess,Php,Jquery,Mysql,Ajax,.htaccess,我有这些关于.htaccess的AJAX帖子问题。在我在.htaccess中添加了一些规则后,AJAX似乎不会响应php文件,即在.php文件末尾删除并添加斜杠。下面是我的详细代码 我有这些mysql数据库 我有这些index.php和AJAX,可以在getDetails.php中发布并请求自动完成到我的文本字段中 index.php <!doctype html> <html> <head> <title>AJAX POST</t

我有这些关于.htaccess的AJAX帖子问题。在我在.htaccess中添加了一些规则后,AJAX似乎不会响应php文件,即在.php文件末尾删除并添加斜杠。下面是我的详细代码

我有这些mysql数据库

我有这些index.php和AJAX,可以在getDetails.php中发布并请求自动完成到我的文本字段中

index.php

<!doctype html>
<html>
<head>
    <title>AJAX POST</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href='jquery-ui.min.css' type='text/css' rel='stylesheet' >
    <script src="jquery-3.2.1.min.js" type="text/javascript"></script>
    <script src="jquery-ui.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            $(document).on('keydown', '.username', function() {

                var id = this.id;
                var splitid = id.split('_');
                var index = splitid[1];

                $( '#'+id ).autocomplete({
                    source: function( request, response ) {
                        $.ajax({
                            url: "getDetails.php",
                            type: 'post',
                            dataType: "json",
                            data: {
                                search: request.term,request:1
                            },
                            success: function( data ) {
                                response( data );
                            }
                        });
                    },
                    select: function (event, ui) {
                        $(this).val(ui.item.label);  
                        var userid = ui.item.value;  
                        $.ajax({
                            url: 'getDetails.php',
                            type: 'post',
                            data: {userid:userid,request:2},
                            dataType: 'json',
                            success:function(response){
                                var len = response.length;
                                if(len > 0){
                                    var id = response[0]['id'];
                                    var name = response[0]['name'];
                                    var email = response[0]['email'];
                                    document.getElementById('name_'+index).value = name;
                                    document.getElementById('age_'+index).value = age;                                    
                                }

                            }
                        });

                        return false;
                    }
                });
            });
        });

    </script>
</head>
<body>
    <div class="container">
        <table border='1' style='border-collapse: collapse;'>
            <thead>
            <tr>
                <th>Username</th>
                <th>Name</th>
                <th>Age</th>
            </tr>
            </thead>
            <tbody>
            <tr class='tr_input'>
                <td><input type='text' class='username' id='username_1' placeholder='Enter username'></td>
                <td><input type='text' class='name' id='name_1' ></td>
                <td><input type='text' class='age' id='age_1' ></td>
            </tr>
            </tbody>
        </table>
    </div>
</body>
</html>
<?php
$host = "";  
$user = "";  
$password = "";  
$dbname = "";  
$con = mysqli_connect($host, $user, $password,$dbname);
if (!$con) { die("Connection failed: " . mysqli_connect_error());}

$request = $_POST['request'];
if($request == 1){
    $search = $_POST['search'];
    $query = "SELECT * FROM users WHERE username like'%".$search."%'";
    $result = mysqli_query($con,$query);
    while($row = mysqli_fetch_array($result) ){
        $response[] = array("value"=>$row['id'],"label"=>$row['username']);
    }
    echo json_encode($response);
    exit;
}
// Get details
if($request == 2){
    $userid = $_POST['userid'];
    $sql = "SELECT * FROM users WHERE id=".$userid;
    $result = mysqli_query($con,$sql);
    $users_arr = array();
    while( $row = mysqli_fetch_array($result) ){
        $userid = $row['id'];
        $fullname = $row['fname']." ".$row['lname'];
        $email = $row['email'];
        $users_arr[] = array("id" => $userid, "name" => $fullname,"email" => $email);
    }
    // encoding array to json format
    echo json_encode($users_arr);
    exit;
}
?>
有人能帮我解决这个问题吗?谢谢。

试着这样做

 $.ajax({
       url: 'getDetails/',
       type: 'post',
       data: {userid:userid,request:2},
       dataType: 'json',
       success:function(response){
         .......
如果您注意到了,我删除了getDetails中的.php扩展名。也许是个小问题

 $.ajax({
       url: 'getDetails/',
       type: 'post',
       data: {userid:userid,request:2},
       dataType: 'json',
       success:function(response){
         .......