Skip to content

Commit

Permalink
Set content on the XmlHttpRequest object when sending a DELETE request.
Browse files Browse the repository at this point in the history
Nginx will consistently reply with a 411 - Content-Length Required error when sending a DELETE request with no Content-Length.  Chrome does not send a content-length with a DELETE request unless there is content in the request.  Doesn't look like they're gonna fix it (see https://groups.google.com/a/chromium.org/d/msg/chromium-bugs/tkF4sDBPYrs/DFN1cMs5bo4J).
  • Loading branch information
mjumbewu committed Aug 27, 2012
1 parent 6a60dac commit ee4c5f4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sa_web/static/sa/js/models.js
Expand Up @@ -123,6 +123,13 @@ jQuery(document).ajaxSend(function(event, xhr, settings) {
if (!safeMethod(settings.type) && sameOrigin(settings.url)) { if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
} }

// If this is a DELETE request, explicitly set the data to be sent so that
// the browser will calculate a value for the Content-Length header.
if (settings.type === 'DELETE') {
xhr.setRequestHeader("Content-Type", "application/json");
settings.data = '{}';
}
}); });


// Disable caching for all ajax calls. This is required because IE // Disable caching for all ajax calls. This is required because IE
Expand Down

0 comments on commit ee4c5f4

Please sign in to comment.