ajax.url()
Get / set the URL that DataTables uses to Ajax fetch data.
Description
While the ajax.reload()
option makes it very easy to simply reload data from the existing data source, there are times when you want to change the data source URL. This method is design to fit that purpose. It can also be used to retrieve the currently set Ajax data source URL for a table.
Note that when setting a URL you will normally want to chain the ajax.url().load()
method to immediately load the newly set data source URL - using ajax.url()
method alone does not trigger an Ajax request, it merely sets the Ajax data source URL.
Types
function ajax.url()
- Returns:
URL set as the Ajax data source for the table.
Note that if the Api instance refers to multiple tables, only the Ajax data source URL of the first table in the instance is returned. Use
table()
if you require to select a specific table from a set.
function ajax.url( url )
- Parameters:
Name Type Optional 1 url
No URL to set to be the Ajax data source for the table.
- Returns:
DataTables.Api instance
Examples
Get the current Ajax data source URL:
var table = new DataTable('#myTable', {
ajax: 'data.json'
});
alert('Data source: ' + table.ajax.url()); // Will show 'Data source: data.json'
Set the Ajax URL and load the data from the new source immediately:
var table = new DataTable('#myTable', {
ajax: 'data.json'
});
table.ajax.url('newData.json').load();
Related
The following options are directly related and may also be useful in your application development.