Data parameter for Ajax source
Data parameter for Ajax source
I want to use Datatables in wordpress to manage information in MySQL in a cloud server. I have a PHP function in the cloud server that receives a parameter in the data parameter of the POST function in Ajax (actually, I am using jQuery.Post). But I cannot found any way to fill the parameter. One option would be to call the post function, and then use the result to create the table, but is not working (I do not get any errors, but no data is loaded although I have athe data already in the javascript variable), maybe because I would use javascript array as a source, but I suppose I need to set processing and serverside. ¿Is any way to set the data parameter of Ajax POST? ¿Or a way to do server processing but having the data from another source? Thanks
This is the javascript using a previous Ajax call
jQuery(document).ready(function() {
var dataSet;
var r = jQuery.post("/wp-includes/fnbdatos.php",
{"funcion":"execQMultA", "param1":"select pais, nom_pais, nom_corto_pais, continente from Paises "},
function(d) {
dataSet = d;
});
jQuery('paises').DataTable({
ajax: {
processing: true,
serverSide: true,
dataSrc: dataSet
}
});
});
This is the javascript using only ajax in DataTable, but no place to send the SQL Query
jQuery(document).ready(function() {
jQuery('paises').DataTable({
ajax: {
url: "/wp-includes/fnbdatos.php",
processing: true,
serverSide: true,
dataSrc: "datos"
}
});
});
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Sounds like you want to use
ajax.data
. See this example.Note - do not use
serverSide
unless your PHP script actually supporters server-side processing. That has a specific meaning in DataTables terminology. You can load JSON data from the server without that option. Only useserverSide
if you have at least tens of thousands of rows.Allan
Thank, also, type = 'Post' was required