<?xml version="1.0" encoding="UTF-8" ?>
<dt-event>
	<name>xhr</name>
	<summary>Ajax event - fired when an Ajax request is completed</summary>
	<since>1.10</since>

	<type type="function">
		<signature>function( e, settings, json, xhr )</signature>
		<parameter type="object" name="e">
			jQuery event object
		</parameter>
		<parameter type="DataTables.Settings" name="settings">
			DataTables settings object
		</parameter>
		<parameter type="object" name="json">
			Data returned from the server. This will be `-type null` if triggered by the Ajax error callback.
		</parameter>
		<parameter type="object" name="xhr" since="1.10.7">
			[jQuery XHR](http://api.jquery.com/Types/#jqXHR) object that can be used to access the low level Ajax options.
		</parameter>
		<return type="boolean">
			Since 1.10.7 you can return `true` to indicate to DataTables that it should not trigger its `dt-event error` event if you have handled an error condition yourself.
		</return>
		<scope>HTML table element</scope>
	</type>

	<description>
		When working with Ajax data, it is often useful to know when DataTables has completed the loading of data, so you can either manipulate that data into the format DataTables expects based upon its configuration (`dt-init columns.data`) or so you can use the data contained in the JSON response from the server for other parts of the page.

		This event can be seen as the event complement to the `dt-init ajax.dataSrc` option (which can also be used to manipulate and intercept the data from the Ajax request). Generally you would want to do data manipulation in the `dataSrc` callback and use events for intercepting the data.

		Note that this event is called before DataTables has processed the new data from the server, so the returned data will not have been drawn on page when this event fires.

		Additionally, as of DataTables 1.10.7 this event is triggered by both success and error conditions when the Ajax request completed (i.e. it is always triggered regardless of the outcome of the Ajax request). Prior to 1.10.7 it was only triggered by a successful request. The `json` parameter (3rd passed in) for the event handler will be `null` if an error has occurred and the `xhr` parameter (4th) can be used to determine the error details if required.

		Please note that, as with all DataTables emitted events, this event is 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.
	</description>

	<example title="Pre-process the data returned from the server"><![CDATA[
$('#example')
	.on('xhr.dt', function ( e, settings, json, xhr ) {
		for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
			json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
		}
		// Note no return - manipulate the data directly in the JSON object.
	} )
	.dataTable( {
		ajax: "data.json"
	} );
]]></example>

	<example title="Use a custom property returned from the server in another DOM element"><![CDATA[
$('#example')
	.on('xhr.dt', function ( e, settings, json, xhr ) {
		$('#status').html( json.status );
	} )
	.dataTable( {
		ajax: "data.json"
	} );

]]></example>

	<related type="option">ajax</related>
	<related type="api">ajax.json()</related>
	<related type="api">ajax.url()</related>
	<related type="api">ajax.reload()</related>
	<related type="event">preXhr</related>
</dt-event>