Enyo AJAX

by Art Dahm

JavaScript

enyo.kind({
    name: "App",
    style: "padding-left:20px; padding-top:20px;",
    components: [
        {name: "tempService", kind: "enyo.WebService", url: "http://art.dlinkddns.com:8081/temp", onResponse: "showTemp", onError: "failure", jsonp: true, callbackName: "callback"},
        {name: "result", content: "Tap button for temperature."},
        {kind: "enyo.Button", content: "Temperature", ontap: "getTemp"}
    ],
    
    getTemp: function() {
        this.$.result.setContent("Getting temp...");
        this.$.tempService.send();
    },
    
    showTemp: function(inSender, inResponse) {
        this.$.result.setContent(inResponse.data.f + " degrees");
    },
    
    failure: function() {
        this.$.result.setContent("Failure!");
    }
});

new App().renderInto(document.body);