We've written a RESTful server API. For whatever reason, we made the decision that for DELETEs, we would like to return a 204 (No Content) status code, with an empty response. I'm trying to call this from jQuery, passing in a success handler and setting the verb to DELETE:
jQuery.ajax({
type:'DELETE',
url: url,
success: callback,
});
The server returns a 204, but the success handler is never called. Is there a way I can configure jQuery to allow 204s to fire the success handler?
It's technically a problem on your server
Like Paul said, an an empty 204 response with a server content-type of json is treated by jQuery as an error.
You can get around it in jQuery by manually overriding dataType to 'text'.
$.ajax({
url: url,
dataType:'text',
success:(data){
//I will now fire on 204 status with empty content
//I have beaten the machine.
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With