Skip to content

Instantly share code, notes, and snippets.

@mattparlane
Created March 25, 2014 06:19
Show Gist options
  • Save mattparlane/9756121 to your computer and use it in GitHub Desktop.
Save mattparlane/9756121 to your computer and use it in GitHub Desktop.
done() handler not firing for DELETE request when Content-Type header is set
require 'sinatra'
get '/' do
'
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js></script>
<script>
$(function() {
$("a").click(function() {
var url = $(this).data("url");
$.ajax({
type: "delete",
url: url,
})
.done(function() {
console.log("win");
})
.fail(function() {
console.log("fail");
});
return false;
});
});
</script>
<body>
<a href=# data-url="/fail">fail</a>
<a href=# data-url="/win">win</a>
</body>
'
end
delete '/fail' do
[200, {'Content-Type' => 'application/json'}, '']
end
delete '/win' do
# either of these work:
[204, {'Content-Type' => 'application/json'}, '']
[200, {}, '']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment