(function(root) { 'use strict'; function sendQuery(url, error, success) { var xmh = new XMLHttpRequest(); var v; xmh.onreadystatechange = function() { v = xmh.responseText; if (xmh.readyState === 4 && xmh.status === 200) { var res; try { res = JSON.parse(v); } catch (err) { if (null !== error) error(err.name, err.message); } if (null !== success) success(res); } else if (xmh.readyState === 4) { if (null !== error) error(xmh.status, v); } }; xmh.open('GET', url, true); xmh.send(null); } function stdError(code, resp) { console.log('ERROR ' + code + ': ' + resp); } function indexSuccess(resp) { app.books = resp; app.booksCount = app.books.length; } function loadIndex() { sendQuery('cgi-bin/bouquins/books', stdError, indexSuccess); } root.loadIndex = loadIndex; })(this); var app = new Vue({ el: '#app', data: { books: [], booksCount: 0 }, mounted: function() { loadIndex(); } })