function lightswitch()
{
    id = this.id.replace("light_", "");
    $.post("/lightswitch", { id: id })
        .fail(location.reload());
};

$(document).ready(function () {
    $(".toggle").each(function(index) {
        obj = $(".toggle")[index];
        document.querySelector('#' + obj.id).addEventListener('toggle', lightswitch, obj.id);
    });
});

function lightswitch()
{
    id = this.id.replace("light_", "");
    $.post("/lightswitch", { id: id });
};

$(document).ready(function () {
    $(".toggle").each(function(index) {
        obj = $(".toggle")[index];
        document.querySelector('#' + obj.id).addEventListener('toggle', lightswitch, obj.id);
    });
});

--- 
+++ 
@@ -1,8 +1,7 @@
 function lightswitch()
 {
     id = this.id.replace("light_", "");
-    $.post("/lightswitch", { id: id })
-        .fail(location.reload());
+    $.post("/lightswitch", { id: id });
 };
 
 $(document).ready(function () {
Handle failure to toggle light

Handle it by reloading the entire page. A little crude, sure, but it
does at least work.
