You can access the data property of the ajax options inside the error handler with just this.data.
If you don't specifically set the context property, this inside the callbacks for $.ajax will always be the ajax call itself, and then this.data will be the serialized string of the data you passed in.
$.ajax({
type : 'POST',
url : 'addToBasket.php',
data : 'id='+id,
error : function(xhr, textStatus, error){
var data = this.data; // "id=something"
},
success : function(data, textStatus, xhr){}
});
FIDDLE
If you need to parse that string into an object, here's how -> How can I get query string values in JavaScript?
You could also use the global error handler to get the data object, as it the ajax call as it's first argument.
It will fire on all ajax errors, but can be filtered by URL or any other option passed etc.
$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
if (ajaxSettings.url == 'addToBasket.php') {
alert(ajaxSettings.data)
}
});
FIDDLE