Error including php file on ajax call
Error including php file on ajax call
Hello,
Im loading the data for a table with ajax, the script looks like this:
$(document).ready(function() {
$('#fact_table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "facts/views/modules/factsAjax.php",
"type": "POST"
}
} );
} );
In the factsAjax.php Im including a controller to manage the database access and process the data to return a json format-like structure. This is the current code on factsAjax.php
<?php
require ('facts/controllers/factsController.php');
$jsonResult = new FactController();
$jsonResult -> viewFactController();
But when I reload the page where the fact_table is I get the error "DataTables warning: table id=fact_table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"
I tested the script that returns the json and validate it in order to bulk the result to a text file so I was able to use it as the data source. This actually works, so then I used again the factsAjax.php file as the data source, opened the developers tools and found that factsAjax.php is not properly loading factsController.php. This is the factsAjax response:
<br />
<b>Warning</b>: require(facts/controllers/factsController.php): failed to open stream: No such file or directory in <b>C:\xampp\htdocs\main\facts\views\modules\factsAjax.php</b> on line <b>2</b><br />
<br />
<b>Fatal error</b>: require(): Failed opening required 'facts/controllers/factsController.php' (include_path='C:\xampp\php\PEAR') in <b>C:\xampp\htdocs\main\facts\views\modules\invoiceAjax.php</b> on line <b>2</b><br />
Any suggestions?
Answers
That has nothing to do with DataTables. When a file is not being found it is a matter for you to rectify within your file system.
I assumed this is a DataTables issue since the file is correctly loaded in many other instances of my application.
DataTables itself is a Javascript library, so tangerine is correct is saying that this isn't caused by DataTables - although obviously you are seeing it through your use of DataTables.
Without knowing the file structure on your server I can't say exactly what the issue is, but it sounds like the include path for
factsController.php
infactsAjax.php
isn't quite right. Perhaps its just looking in the wrong directory, or it needs a leading$_SERVER['DOCUMENT_ROOT']
or similar.Allan