jQuery: usare il metodo ajax() con i Deferred Object

Con l'introduzione dei Deferred Object è cambiato anche il modo di usare questo metodo low level di jQuery.

Il modo consigliato è il seguente:


$.ajax({
	url: "ajax.php",
	type: "post",
	dataType: "json",
	data: {
		str: "Test"
	}
}).done(function( response ) {
	// La richiesta ha avuto successo
}).fail(function( xhr, status, error ) {
	// La richiesta non ha avuto successo
});

Torna su