This uses jQuery and the LiveQuery plugin to take anchors with a method attribute and create a hidden form that allows the information the be submitted via POST.

By ezmobius

JS:

  $('a[method]').livequery(function(){
    var message = $(this).attr('confirm');
    var method  = $(this).attr('method');
 
    if (!method && !message) return;
 
    $(this).click(function(event){
      if (message && !confirm(message)) {
        event.preventDefault();
        return;
      }
 
      if (method == 'post' || method == 'put' || method == 'delete') {
        event.preventDefault();
 
        var form = $("<form/>").attr('method', 'post').attr('action', this.href).attr('style', 'display: none');
 
        if (method != "post") {
          form.append($('<input type="hidden" name="_method"/>').attr('value', method));
        }
        form.insertAfter(this).submit();
      }
    });
  });
 
snippets/anchor-post.txt · Last modified: 2009/01/07 16:24 by qhoxie