How to use inline Ajax data source (arrays)
How to use inline Ajax data source (arrays)
vbkk
Posts: 8Questions: 1Answers: 0
Link to test case: http://live.datatables.net/lodicoku/1/edit
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: The table not shown the data.
This discussion has been closed.
Answers
Yep,
ajax
expects a URL to be given, which DataTables calls to get the data - see example here.Colin
Colin,
why the data is not processed here at http://live.datatables.net/lodicoku/1/edit ?
You have this:
"data"
is not a valid URL. You need a URL pointing to a server. If you want to add data from a Javascript variable use thedata
option, for example:https://datatables.net/examples/data_sources/js_array.html
If this doesn't help please provide more information of what you are trying to do. What do you expect
"ajax": "data"
to do?Kevin
Colin,
Kevin,
Is it possible to load or process the data from the same page ?
Kevin already gave you an example.
Hi,
I am not clear and not get the logic because may be i am logic less at this moment due to insufficient knowledge about the matter.
Once again my question here as follows
Is it possible to load or process the data from the same page ?
as mention the data as ajax and put the data on the same page like js array shown above by kevin.
Sorry I don't understand what you mean by "data from the same page". PLease provide more details. These examples show the ways data can be loaded into Datatables:
https://datatables.net/examples/data_sources/index.html
The Data docs describe these options.
Kevin
Hi,
as mentioned at https://datatables.net/examples/data_sources/ajax.html
with
<!DOCTYPE html>
$(document).ready(function() { $('#example').DataTable( { "ajax": "./data.txt" } ); } );<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
</body>
</html>
and separate data file as
"ajax": "./data.txt"
as
"draw": 1,
"recordsTotal": 4,
"recordsFiltered": 4,
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
],
[
"Ashton Cox",
"Junior Technical Author",
"San Francisco",
"1562",
"2009/01/12",
"$86,000"
],
]
}
not working.
The URL given in the
ajax
option needs to point to a webserver. For security reasons the web browser won't allow direct access to the file system.Kevin
Hi All,
May be my question is logic less ?
The
ajax
option uses jQuery ajax which uses an HTTP request to fetch the data. Do you have a web server setup for the HTTP requests? If you do have a web server setup then you will need to verify the path to the file.If you are not familiar with how ajax works then maybe this tutorial will help:
https://www.w3schools.com/xml/ajax_intro.asp
Kevin
Hi All,