Git Product home page Git Product logo

submit's Introduction

work-in-progress

Submit v0.5

[Plug-in for jQuery][plugin] 1.3 or higher

HTML forms lack support for PUT and DELETE idempotent HTTP methods and browsers often simply downgrade to safe GET. An unpleasant aspect of going CRUDe and RESTful.

Submit aims to bridge this gap by performing the <form> submit via jQuery's reliant AJAX implementation. Thus handling methods properly and preventing the browser from downgrading at the same time. Submit is eventful and super thin (1k!). Ideal for RESTful applications.

Download:

jquery.submit -min.js (1.067 kb), .js (1.696 kb) or the entire .zip


Classname-based Initialization

No Javascript. Just add "jquery-submit" class to your <form> and use any method you like (even PUT or DELETE):

<form class="jquery-submit" method="PUT">

URL in Result

Unlike classic form submission, you don't get your response from the server directly. Instead you always get another URL address. In response to any submit, both success and error, a plain-text response URL is expected. This URL needs to be resolvable with GET. Browser then automatically redirects to the response URL.

AJAX

Submit utilizes standard jQuery's .ajax method to deliver over the network. You can therefore use all its available settings. Assign them as properties of $.submit.ajaxSettings object.

+ Bonus

Submit Without Leaving

You can very easily submit into a DOM element without leaving the current page. Submit will utilize jQuery's .load() method to load the URL into whatever matches jQuery selector specified in <form>'s target attribute.

<form target="#result" class="jquery-submit" method="PUT">

will submit the form, load the result and render it inside DOM element #result.

Page Fragments

Equally simply you can load only a portion of the response document. By extending the target attribute with < followed by another jQuery selector. The second one is supplied to .load() as the "after the space" selector.

<form target="#result < #section" class="jquery-submit" method="PUT">

will cut-out contents of element #section in the response and render it inside #result.

Events

Submit is event-driven and important moments are announced via the jQuery Event Model and can be listen to.

Prior to the actual form submit a "get-submit", "post-submit", "put-submit" or "delete-submit" event is triggered on the <form>. Bind to these events the usual way. Handler will accept form and method attributes. You can return boolean false from the handler to prevent the form from being submitted.

$('form').bind("put-submit", function(event, form, method){
	return false;
});

You may also return an object of specific settings for the .ajax call. Some of them may get overriden.

$('form').bind("put-submit", function(event, form, method){
	return {
		beforeSend: function(){ ... }
	}
});

Similarly, after completion "get", "post", "put" or "delete" event is triggered on the <form> right before Submit either redirects or loads the response URL. Handler will accept form, result and url attributes. Return false to prevent it from happening if you want to handle the response by yourself.


Open-source, of course!

Dual licensed under the MIT and GPL licenses. Copyright (c) 2010 Petr Vostrel

Fork me on Github!

submit's People

Contributors

pisi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

submit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.