X-HTTP-Method-Override in jQuery?

coolaj86 picture coolaj86 · Nov 28, 2009 · Viewed 8k times · Source

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

Answer

Darin Dimitrov picture Darin Dimitrov · Nov 28, 2009

You could set custom headers when performing an ajax request by using the beforeSend callback:

$.ajax({
    beforeSend: function(xhr) {
        xhr.setRequestHeader('X-HTTP-Method-Override', 'PUT');
    },
    type: 'POST',
    url: '/someurl',
    success: function(data){
        // do something...
    }
});