refresh var inside ajax data
refresh var inside ajax data
Hello, I am using datatable together with ajax and jquery, in a php environment, I present the case
When loading the content I load a var of value o and the ajax call of dataable, at this point it is correct
this code
var idReg=0;
var tableReg = $('#ListRegistro').DataTable(
{
"ajax": {
"url": UrlBase+"?type=4",
"contentType": "application/json",
"type": "GET",
"data": {idServicio:idReg},
"success": function ( d ) {
return JSON.stringify( d );
}
}
} );
Additionally, I have a function that changes the value of idReg, and it changes it correctly, but if I do an ajax.refresh, the data table request has not updated that variable...how can I update it or create that dynamic var?
thank you
Edited by Colin - 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
Two things - first, as discussed on the page
ajax
,success
must not be overridden as it's used internally by DataTables.Secondly, you can use
ajax.dataSrc
to achieve what you want. This can be a function, so you can dynamically change where the data presides. Likewise, you can do the same with a function forajax.data
,Colin
Could you show me an example please?
For
idReg
use:Then the function will be evaluated whenever you make an Ajax request.
For the first part, can you show me a sample of the JSON data being sent back by the server?
Allan
Thanks its Works!!
thanks