Git Product home page Git Product logo

vue-ajax-form-component's Introduction

vue-ajax-form-component

A Vue.js component for creating simple AJAX forms.

Install

Available through npm as vue-ajax-form-component. Or include as an inline script, like in example.html.

Demo

You can load up the example.html file here to test the directive. Just make sure you put this folder in a server that has PHP. Or you can change the ajax-form action attribute to point to your API endpoint.

Usage

Minimal:

<ajax-form action="submit.php">
  <!-- normal stuff that goes in a form. Ex: inputs, selects, radio/checkboxs etc. -->
</ajax-form>

Full Example:

<ajax-form id="formOne" class="my-form" name="myCoolForm" action="submit.php" method="post" v-response-type="json">
  <!-- normal stuff that goes in a form. Ex: inputs, selects, radio/checkboxs etc. -->
</ajax-form>

You can see a custom attribute called v-response-type. This allows you to set the response type for your form. Most cases you will be expecting JSON in return, and then sending that to some variable in your Vue data.

But, sometimes maybe you are expecting back some HTML or some raw text. In those cases, you can use v-response-type="html" or v-response-type="text", respectively. Then you could maybe dump the results in your view in some area. A use case for this might be for "session" flashes like success or error alerts, or maybe a preview of a blog post.

You can see a Vue instance example in example.html if you want more details.

Support

This component assumes you have support for FormData and the XHR progress event.

vue-ajax-form-component's People

Contributors

james2doyle avatar rajabishek avatar

Watchers

 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.