Skip to content

Latest commit

 

History

History
82 lines (55 loc) · 1.99 KB

README.md

File metadata and controls

82 lines (55 loc) · 1.99 KB

<ajax-element>

VanillaJS Ajax Web Component

Demo

Check it live!

Install

Install the component using Bower:

$ bower install ajax-element --save

Or download as ZIP.

Usage

  1. Import Web Components' polyfill:

    <script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
  2. Import Custom Element:

    <link rel="import" href="bower_components/ajax-element/src/ajax-element.html">
  3. Listen for Events:

    <script>
      document.getElementById('myID').addEventListener('ajaxElementSuccess', function (event) {
        document.getElementById('anotherID').textContent = event.detail.data;
      });
    
      document.getElementById('myID').addEventListener('ajaxElementError', function (event) {
        document.getElementById('anotherID').textContent = event.detail.data;
      });
    </script>
  4. Start using it!

    <ajax-element url="http://www.example.com"></ajax-element>

Options

Attribute Options Default Description
url string `` The Request URL.
type string GET The Request Method.
datatype string `` Set to json to parse response as JSON.
data string `` Set to serialized data to send with POST requests.

##TODO

  1. Promises
  2. State Indicators
  3. Mock Server for Demos

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

For detailed changelog, check Releases.

License

MIT License