Search code examples
jqueryhttp-headersput

X-HTTP-Method-Override in jQuery?


How can I do an X-HTTP-Method-Override for an ajax request in jQuery?


Solution

  • With 1.5 you can now pass in a headers option:

    $.ajax({
      headers: {
        'X-HTTP-Method-Override': 'DELETE'
      },
      method: 'GET'
      // more parameters...
    });
    

    This is set before 'beforeSend' is called, so it could still get overwritten. See http://api.jquery.com/jQuery.ajax/

    -- fixed incorrect syntax (wouldn't let me save with less than 6 character edit, so writing this message