Skip to content

AndersDJohnson/jquery-methodOverride

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jquery-methodOverride

More HTTP methods for jQuery.ajax, emulated for cross-browser support. Enhance forms with method overrides.

Great for integrating with a RESTful API (see Framework support).

Uses conventions like the X-HTTP-Method-Override header and the hidden _method parameter to proxy the lesser-used methods through the fully-supported GET and POST.

Proxied methods

The "useful" methods from RFC 2616 are supported, proxied as follows:

  • PUT: POST
  • PATCH: POST
  • DELETE: POST
  • HEAD: GET
  • OPTIONS: GET

Install

Via bower as jquery-methodOverride.

bower install --save jquery-methodOverride

Usage

Include on your page, after jQuery. Supports AMD.

Methods

The following methods will become available, which simultaneously support both $.ajax and $.get/$.post APIs.

$.put(/* ... */);
$.patch(/* ... */);
$.delete(/* ... */);
$.head(/* ... */);
$.options(/* ... */);

For API details, refer to:

Forms

To enhance a form with method override, use $.fn.methodOverride.

Example

Given the following form:

<form method="put">
  <!-- ... -->
</form>

And adding the following script:

$('form').methodOverride();

Will result in the following enhanced form:

<form method="POST" data-method-override="put">
  <!-- ... -->
  <input type="hidden" name="_method" value="put">
</form>

Utility

  • $.fn.methodOverride.map: function (method:String) : String

    Maps a method to its override method, if any.

  • $.fn.methodOverride.methods: Object.<String>

    The raw object mapping methods to their override methods.

Framework support

About

More HTTP methods for jQuery.ajax and forms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published