Giter Site home page Giter Site logo

jquery.tao.js's Introduction

jquery.tao.js - Form AJAXizer

About

Tao is your new best friend. With his zen attitude and his grand master skills, he will help you turn old-fashioned forms to AJAX beauties in a second.

Consider the following form :

<form class="boring" method="POST" action="/target/url">
    <input type="text" name="textfield" value="my value" />
    <input type="checkbox" name="tick" value="1" checked />
    <button type="submit">Go</button>
</form>

When your user presses the button, his browser will hit /target/url with the POST method, sending along the value of all the fields in the form (here, a textfield and a checkbox), which triggers a page reload.

What if we could just skip that last part to handle the view update by ourselves in a modern, SPA-way ?

var $form = $('form.boring');

$form.tao({
    data: {
        // add extra data : useful if you have no way
        // to tell an AJAX request apart, server-side
        ajax: 1
    },

    submit: function() {
        // need an extra callback on form's submit event ?
        console.log('I am called when you submit the form');
    },

    success: function(data) {
        console.log('I love this plugin');
        form.removeClass('boring').addClass('awesome');
    }
});

Tao takes an object as a parameter, which members are the same as for a classic $.ajax call (which means you will essentially put your success/error callbacks here, in a way you already know). So you can specify any option for $.ajax right there.

Tao will use your form's method attribute as the request method (type in jQuery terminology), and its action attribute as the target URL... unless you specified some yourself in the options as explained right above.

Tao is fast, lightweight, straightforward. What are you waiting for ?

Build

Tao is built using Grunt. Simply run grunt at the project root to run the source through JSHint and uglify it into the dist folder.

jquery.tao.js's People

Contributors

neemzy avatar

Stargazers

Emmanuel Salomon avatar Matt Soria avatar

Watchers

James Cloos avatar  avatar  avatar

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.