Request.HTML

Sends HTML code to backend updates target div and executes <script>

by Dimitar Christoff

HTML

<div id='target_div'>Target</div>

JavaScript

var timer;

new Request.HTML({
    url: '/ajax_html_echo/',
    data: {
        'html': "request complete"
    },
    method: 'post',
    update: 'target_div',
    onRequest: function() {
        timer = (function() {
            document.id("target_div").set("html", "<img src='http://straval.com/img/ajax-spinner-large.gif' />");
        }).delay(500);
    },
    onSuccess: function(response) {
        $clear(timer);

    }
}).send();