DataTables警告:table id = table_companies - 无效的JSON响应。有关此错误的更多信息,请参阅http://datatables.net/tn/1

时间:2018-01-12 07:28:19

标签: php mysqli datatables

请帮帮我。我在这里有一个错误,我不知道为什么每次刷新页面时都会发出错误提示,

  

DataTables警告:table id = table_companies - 无效的JSON响应。   有关此错误的详细信息,请参阅   http://datatables.net/tn/1

帮助我。我不知道接下来会做什么病

  

这是我的ajax

<?php
// Database details
$db_server   = 'localhost';
$db_username = 'root';
$db_password = '';
$db_name     = 'dmsregister';

// Get document (and doc_id)
$document = '';
$doc_id  = '';
if (isset($_GET['document'])){
  $document = $_GET['document'];
  if ($document == 'get_document' ||
      $document == 'get_document'   ||
      $document == 'add_document'   ||
      $document == 'edit_document'  ||
      $document == 'delete_document'){
    if (isset($_GET['doc_id'])){
      $doc_id = $_GET['doc_id'];
      if (!is_numeric($doc_id)){
        $doc_id = '';
      }
    }
  } else {
    $document = '';
  }
}

// Prepare array
$mysql_data = array();

// Valdoc_id document found
if ($document != ''){

  // Connect to database
  $db_connection = mysqli_connect($db_server, $db_username, $db_password, $db_name);
  if (mysqli_connect_errno()){
    $result  = 'error';
    $message = 'Failed to connect to database: ' . mysqli_connect_error();
    $document    = '';
  }

  // Execute document
  if ($document == 'get_document'){

    // Get companies
    $query = "SELECT * FROM blgd ORDER BY doc_id";
    $query = mysqli_query($db_connection, $query);
    if (!$query){
      $result  = 'error';
      $message = 'query error';
    } else {
      $result  = 'success';
      $message = 'query success';
      while ($document = mysqli_fetch_array($query)){
        $functions  = '<div class="function_buttons"><ul>';
        $functions .= '<li class="function_edit"><a data-doc_id="'   . $document['doc_id'] . '" data-name="' . $document['program'] . '"><span>Edit</span></a></li>';
        $functions .= '<li class="function_delete"><a data-doc_id="' . $document['doc_id'] . '" data-name="' . $document['program'] . '"><span>Delete</span></a></li>';
        $functions .= '</ul></div>';
        $mysql_data[] = array(
          "date"          => $document['date'],
          "program"  => $document['program'],
          "doc_type"    => $document['doc_type'],
          "doc_title"       => $document['doc_title'],
          "recieved"   => $document['recieved'],
          "date_recieved"     => $document['date_recieved'],
          "remarks"    => $document['remarks'],
          "functions"     => $functions
        );
      }
    }

  } elseif ($document == 'get_document'){

    // Get document
    if ($doc_id == ''){
      $result  = 'error';
      $message = 'doc_id missing';
    } else {
      $query = "SELECT * FROM blgd WHERE doc_id = '" . mysqli_real_escape_string($db_connection, $doc_id) . "'";
      $query = mysqli_query($db_connection, $query);
      if (!$query){
        $result  = 'error';
        $message = 'query error';
      } else {
        $result  = 'success';
        $message = 'query success';
        while ($document = mysqli_fetch_array($query)){
          $mysql_data[] = array(
            "date"          => $document['date'],
            "program"  => $document['program'],
            "doc_type"    => $document['doc_type'],
            "doc_title"       => $document['doc_title'],
            "recieved"   => $document['recieved'],
            "date_recieved"     => $document['date_recieved'],
            "remarks"    => $document['remarks'],

          );
        }
      }
    }

  } elseif ($document == 'add_document'){

    // Add document
    $query = "INSERT INTO blgd SET ";
    if (isset($_GET['date']))         { $query .= "date         = '" . mysqli_real_escape_string($db_connection, $_GET['rank'])         . "', "; }
    if (isset($_GET['program'])) { $query .= "program = '" . mysqli_real_escape_string($db_connection, $_GET['document_name']) . "', "; }
    if (isset($_GET['doc_type']))   { $query .= "doc_type   = '" . mysqli_real_escape_string($db_connection, $_GET['industries'])   . "', "; }
    if (isset($_GET['doc_title']))      { $query .= "doc_title      = '" . mysqli_real_escape_string($db_connection, $_GET['revenue'])      . "', "; }
    if (isset($_GET['recieved']))  { $query .= "recieved  = '" . mysqli_real_escape_string($db_connection, $_GET['fiscal_year'])  . "', "; }
    if (isset($_GET['date_recieved']))    { $query .= "date_recieved    = '" . mysqli_real_escape_string($db_connection, $_GET['employees'])    . "', "; }
    if (isset($_GET['remarks']))   { $query .= "remarks   = '" . mysqli_real_escape_string($db_connection, $_GET['market_cap'])   . "', "; }
    $query = mysqli_query($db_connection, $query);
    if (!$query){
      $result  = 'error';
      $message = 'query error';
    } else {
      $result  = 'success';
      $message = 'query success';
    }

  } elseif ($document == 'edit_document'){

    // Edit document
    if ($doc_id == ''){
      $result  = 'error';
      $message = 'doc_id missing';
    } else {
      $query = "UPDATE blgd SET ";
      if (isset($_GET['date']))         { $query .= "date         = '" . mysqli_real_escape_string($db_connection, $_GET['rank'])         . "', "; }
      if (isset($_GET['program'])) { $query .= "program = '" . mysqli_real_escape_string($db_connection, $_GET['document_name']) . "', "; }
      if (isset($_GET['doc_type']))   { $query .= "doc_type   = '" . mysqli_real_escape_string($db_connection, $_GET['industries'])   . "', "; }
      if (isset($_GET['doc_title']))      { $query .= "doc_title      = '" . mysqli_real_escape_string($db_connection, $_GET['revenue'])      . "', "; }
      if (isset($_GET['recieved']))  { $query .= "recieved  = '" . mysqli_real_escape_string($db_connection, $_GET['fiscal_year'])  . "', "; }
      if (isset($_GET['date_recieved']))    { $query .= "date_recieved    = '" . mysqli_real_escape_string($db_connection, $_GET['employees'])    . "', "; }
      if (isset($_GET['remarks']))   { $query .= "remarks   = '" . mysqli_real_escape_string($db_connection, $_GET['market_cap'])   . "', "; }
      $query .= "WHERE doc_id = '" . mysqli_real_escape_string($db_connection, $doc_id) . "'";
      $query  = mysqli_query($db_connection, $query);
      if (!$query){
        $result  = 'error';
        $message = 'query error';
      } else {
        $result  = 'success';
        $message = 'query success';
      }
    }

  } elseif ($document == 'delete_document'){

    // Delete document
    if ($doc_id == ''){
      $result  = 'error';
      $message = 'doc_id missing';
    } else {
      $query = "DELETE FROM blgd WHERE doc_id = '" . mysqli_real_escape_string($db_connection, $doc_id) . "'";
      $query = mysqli_query($db_connection, $query);
      if (!$query){
        $result  = 'error';
        $message = 'query error';
      } else {
        $result  = 'success';
        $message = 'query success';
      }
    }

  }

  // Close database connection
  mysqli_close($db_connection);

}

// Prepare data
$data = array(
  "result"  => $result,
  "message" => $message,
  "data"    => $mysql_data
);

// Convert PHP array to JSON array
$json_data = json_encode($data);
print $json_data;
?>
  

PHP文件

<?php
// Initialize the session
session_start();

// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
  header("location: indexlogin.php");
  exit;
}

 echo "welcome".$_SESSION['username'];
?>

<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <title>BLGD DOCUMENT MANAGEMENT SYSTEM</title> 
    <meta charset="utf-8">
    <meta name="viewport" content="width=1000, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Oxygen:400,700">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="layout.css">
    <script charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script charset="utf-8" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>
    <script charset="utf-8" src="//cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.min.js"></script>
    <script charset="utf-8" src="webapp.js"></script>
  </head>
  <body>

    <div id="page_container">

      <h1>BLGD DOCUMENT MANAGEMENT SYSTEM</h1>

      <button type="button" class="button" id="add_company">Add Document</button>

      <table class="datatable" id="table_companies">
        <thead>
          <tr>
            <th>Document ID</th>
            <th> date</th>
            <th>Program</th>
            <th>document type</th>
            <th>Document Title</th>
            <th>recieved by</th>
            <th>date recieved</th>
            <th>Remarks</th>
            <th>Functions</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>

    </div>

    <div class="lightbox_bg"></div>

    <div class="lightbox_container">
      <div class="lightbox_close"></div>
      <div class="lightbox_content">

        <h2>Add Document</h2>
        <form class="form add" id="form_company" data-id="" novalidate>
          <div class="input_container">
            <label for="rank">date <span class="required">*</span></label>
            <div class="field_container">
              <input type="date"  class="text" name="date" id="date" value="" required>
            </div>
          </div>
          <div class="input_container">
            <label for="company_name">Program <span class="required">*</span></label>
            <div class="field_container">
                <select name="program" value="" placeholder="select a program" id="program">
              <option name="program">Performance Challenge Fund </option>
              <option name="program"> Gender and Development </option>
              <option name="program"> Other Interagency Program </option>
</select>
            </div>
          </div>
          <div class="input_container">
            <label for="doc_type">Document Type <span class="required">*</span></label>
            <div class="field_container">
            <select name="doc_type" value="" placeholder="select a document type" id="doc_type">
              <option name="doc_type">Memorandum </option>
              <option name="doc_type"> Department Order </option>
              <option name="doc_type"> Bureau Order </option>
              <option name="doc_type"> advisory </option>
              <option name="doct_type"> report </option>
              <option name="doc_type"> Activity Design </option>
              <option name="doc_type"> Others </option> 
</select>
            </div>
          </div>
          <div class="input_container">
            <label for="doc_title">Document Title <span class="required">*</span></label>
            <div class="field_container">
              <input type="text"  class="text" name="doc_title" id="doc_title" value="" required>
            </div>
          </div>
          <div class="input_container">
            <label for="recieved">Recieved by <span class="required">*</span></label>
            <div class="field_container">
              <input type="text"  class="text" name="recieved" id="recieved" value="" required>
</div>
          </div>
          <div class="input_container">
            <label for="date_recieved">Date Recieved <span class="required">*</span></label>
            <div class="field_container">
              <input type="date" min="0" class="date" name="date_recieved" id="date_recieved" value="" required>
            </div>
          </div>

          </div>
          <div class="button_container">
            <button type="submit">Add Document</button>
          </div>
        </form>

      </div>
    </div>

    <noscript id="noscript_container">
      <div id="noscript" class="error">
        <p>JavaScript support is needed to use this page.</p>
      </div>
    </noscript>

    <div id="message_container">
      <div id="message" class="success">
        <p>This is a success message.</p>
      </div>
    </div>

    <div id="loading_container">
      <div id="loading_container2">
        <div id="loading_container3">
          <div id="loading_container4">
            Loading, please wait...
          </div>
        </div>
      </div>
    </div>

  </body>
</html>
  

HTML文件

procedure TForm1.Button1Click(Sender: TObject);
var
  IdHTTP: TIdHTTP;
  URL, Str: string;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  URL := 'https://satsis.info/tv/wek/schedule_channel_3_week.html';
  Memo1.Lines.Clear;

  IdHTTP := TIdHTTP.Create(nil);
  try
    IdHttp.HandleRedirects := True;
    SSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
    try
      IdHTTP.IOHandler := SSL;
      Str := IdHTTP.Get(URL);
      Memo1.Text := Str;
    finally
      SSL.Free;
    end;
  finally
    IdHTTP.Free;
  end;
end;

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,只需更改网址即可解决。

http://127.0.0.1:8000/admin/doctors/data/1draw=1&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D

收件人

http://127.0.0.1:8000/admin/doctor/data/1draw=1&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D

医生医生

如果您的问题仍然无法解决,请尝试这样,