Module-documentation

version 1.0.0
module: itsa-io
maintanance: Marco Asbreuk
home
all modules

IO.read()

Get dataobject from the server using ITSA.IO.read().

Click on the button to initiate the request.

Code-example:

<body>
    <div id="container">
        <button id="button-get">Click me get data</button>
    </div>
    <div id="target-container"></div>
</body>
<script src="itsabuild-min.js"></script>
<script>
    var url = 'http://servercors.itsa.io/example',
        container = document.getElementById('target-container'),
        writeResponse, writeResponse;

    writeResponse = function(data) {
        // data should be an object with the `age` property
        var response = '';
        if (Object.isObject(data)) {
            data.each(function(value, key) {
                response += key + ': <b>' + value + '</b><br>';
            });
        }
        container.innerHTML = response;
    };

    errorResponse = function(e) {
        container.innerHTML = e.message;
    };

    ITSA.Event.after(
        'tap',
        function() {
            ITSA.IO.read(url, {example: 2}).then(writeResponse, errorResponse);
        },
        '#button-get'
    );
</script>
API Docs