IfnotFr / RestfulizerJs

A simple jQuery plugin for changing the http method (POST/PUT/DELETE) of a simple html link or button

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RestfulizerJs

_Native POST support and hidden "method" input support for PUT/DELETE

A simple jQuery plugin for changing the http method (POST/PUT/DELETE) of a simple html link or button.

How to use

1: Add the jquery.restfulizer.js file into your project including jQuery.

  <script type="text/javascript" src="js/jquery.restfulizer.js"></script>

2: Use the jQuery method restfulizer() on any link you want to customize the method :

<a href="/user/3" data-method="DELETE" class="rest">link</a>
$(".rest").restfulizer();

Advanced usage

You can also POST links with parameters (and also automatically setup the POST method) :

<a href="/user/create?name=John&age=18&email=test@test.com" class="rest-post">link</a>
$(".rest-post").restfulizer({
        parse: true,
        method: "POST"
});

Full options usage

$(".rest").restfulizer({
        parse: true, // Parse the URL parameters (allow to send them to POST)
        method: "PUT", // The method (POST is native but PUT and DELETE will be simulated with a hidden input called "_method", this solution is handled by many PHP frameworks)
        target: "example.html?specified=yes" // The target (usefull for making non link clickable)
});

About

A simple jQuery plugin for changing the http method (POST/PUT/DELETE) of a simple html link or button

License:MIT License


Languages

Language:HTML 50.9%Language:JavaScript 49.1%