0
votes

it give out:

http://localhost/aps/undefined Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11

//The php code to fetch data
<?php
include('db.php');
$query = '';
$output = array();
$query .= "SELECT * FROM users ";
if(isset($_POST["search"]["value"]))
{
    $query .= 'WHERE first_name LIKE "%'.$_POST["search"]["value"].'%" ';
    $query .= 'OR last_name LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"]))
{
    $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';
}
else
{
    $query .= 'ORDER BY id DESC ';
}
if($_POST["length"] != -1)
{
    $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
    $sub_array = array();
    $sub_array[] = $row["first_name"];
    $sub_array[] = $row["last_name"];
    $sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>';
    $sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>';
    $data[] = $sub_array;
}
$output = array(
    "draw"              =>  intval($_POST["draw"]),
    "recordsTotal"      =>  $filtered_rows,
    "recordsFiltered"   =>  get_total_all_records(),
    "data"              =>  $data
);
echo json_encode($output);
?>

//javasrcipt jquery
var dataTable = $('#user_data').DataTable({
        "processing":true,
        "serverSide":true,
        "order":[],
        "ajax":{
            url:"fetch.php",
            type:"POST"
        },
        "columnDefs":[
            {
                "targets":[0, 3, 4],
                "orderable":false,
            },
        ]

    });
1
Maybe this link help you: stackoverflow.com/questions/15046543/… Did you check if the file is in the right position in htdocs folder of your local webserver - Bernhard Beatus
NO, my ht docs is RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [NC,L] php_flag register_globals 0 php_flag magic_quotes_gpc 0 php_flag magic_quotes_runtime 0 - ubongo
Not the .htaccess settings. I mean if the file is physically in the folder like xampp/htdocs/aps/yourfile.php This is something different. - Bernhard Beatus

1 Answers

0
votes

You can also check if your local webserver is working properly. Just place a file call it e.g. info.php with the following content in xampp/htdocs:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Call it with localhost/info.php in your browser and see if the content is like this: https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page

Check also if your webserver still runs or runs at all.

That's good.

var dataTable = $('#user_data').DataTable({
    paging: true,
    "ajax":{
        url:"fetch.php",
        type:"POST",
         success: function(data, status, xhr) {
        // handle success
         },
         error: function(xhr, status, error) {
           // handle error
         }
        } 
    })
});

Maybe paging: true is the solution.

The 404 Error is related to the ajax call. I found it in the docs. Sorry but I'm not familiar with DataTables. Try to get a specific failure with the handler. You should search and read https://datatables.net/forums/