{hero}

preXhr

Since: DataTables 1.10

Ajax event - fired before an Ajax request is made.

Description

This event is triggered prior to DataTables making an Ajax request to the server for data, and is thus the counterpart to the xhr event which is triggered after the Ajax request has successfully returned data from the server.

The preXhr event is designed for use by plug-in authors who can listen for this event in their extension and send any additional data that might be required. It is very similar to the ajax.data in this ability, with that option typically being used by those writing initialisation code for their table, rather than plug-in authors.

Please note that, as with all DataTables emitted events, the event object has a DataTables API instance available on it (the first parameter). Additionally, the events are triggered with the dt namespace. As such, to listen for this event, you must also use the dt namespace by simply appending .dt to your event name, as shown in the example below.

Type

function function( e, settings, json, xhr )

Parameters:

Example

Send additional data to the server on an Ajax request using an event:

$('#example')
	.on('preXhr.dt', function (e, settings, data) {
		data.sessionId = $('#sessionId').val();
	})
	.DataTable({
		ajax: 'data.json'
	});

// Note that `ajax.data` could also be used to perform this action in this case

Related

The following options are directly related and may also be useful in your application development.