Skip to content

sparksm/ajax-element

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<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

About

VanillaJS Ajax Web Component

Resources

Stars

Watchers

Forks

Packages

No packages published