Hi all,
I'm having an issue with post request. I have two different tables and I need to make a request when users click on the first table.
When an user clicks, a request is sent to the server so that I could draw the info.
So I create one table and add an event to one button on a <span>. When click, I try to reload the second table with:
oTable.ajax().url('http://www.example.com/object.json').load();
Everything seems ok through GET post. Reading in other related posts, I get a solution to make these requests through POST
https://datatables.net/forums/discussion/21940/how-to-pass-new-post-parameters-on-ajax-reload
So I need to pass to ajax.().url() an object with the configuration. I.e.:
object = {url: 'http:www.example.com', type: 'POST', data: {name: 'hey', surname: 'yo'}};
Now I try to get the data through:
oTable.ajax().url(object).load()
First try seems fine but when I try to give to it a second chance, it does not work.
First post: http://www.example.com/getData.php (with POST data)
Second post: http://www.example.com/[Object object] (WRONG PATH)
I found out that in datatable.js line 83104, we get the ajax.url() function definition. There, in the set section, depending on "settings.ajax", the function sets the param called "url" to "settings.ajax" or "settings.ajax.url".
Is that a mistake or a missunderstood from me? ajax.url() is always expecting a String so we could not load new data through POST?
Thank you very much in advance,
Julio
Related links: https://datatables.net/reference/api/ajax.url()
Datatable version: 1.10.11
ajax.url() function:
_api_register( 'ajax.url()', function ( url ) {
var ctx = this.context;
if ( url === undefined ) {
// get
if ( ctx.length === 0 ) {
return undefined;
}
ctx = ctx[0];
return ctx.ajax ?
$.isPlainObject( ctx.ajax ) ?
ctx.ajax.url :
ctx.ajax :
ctx.sAjaxSource;
}
// set
return this.iterator( 'table', function ( settings ) {
// HERE IS THE PROBLEM, IF "URL" is an object instead of an string containing the url
if ( $.isPlainObject( settings.ajax ) ) {
settings.ajax.url = url;
}
else {
settings.ajax = url;
}
// No need to consider sAjaxSource here since DataTables gives priority
// to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
// value of `sAjaxSource` redundant.
} );
} );