<form action="{{ path('cunningsoft_chat_post') }}" method="post">
    <label for="chatMessage">Message</label>
    <input type="text" name="message" id="chatMessage" />
    <input id="submitButton" type="submit" value="submit" />
</form>
{% render(controller('CunningsoftChatBundle:Chat:list')) %}
<script type="text/javascript">
$("#submitButton").submit(function() {
    postMessage();
    updateChat();
    return false;
});
function postMessage()
{
    $.post('{{ path('cunningsoft_chat_post') }}', { 'message': $("#chatMessage").val() });
    $("#chatMessage").val('');
}
function updateChat()
{
    $.post('{{ path('cunningsoft_chat_list') }}', function(data) {
        $('#chat').html(data);
    });
}
setInterval('updateChat()', {{ updateInterval }});
updateChat();
</script>

<form action="{{ path('cunningsoft_chat_post') }}" method="post">
    <label for="chatMessage">Message</label>
    <input type="text" name="message" id="chatMessage" />
    <input id="submitButton" type="submit" value="submit" />
</form>
{% render(controller('CunningsoftChatBundle:Chat:list')) %}
<script type="text/javascript">
$("#submitButton").submit(function() {
    postMessage();
    updateChat();
    return false;
});
function postMessage()
{
    $.post('{{ path('cunningsoft_chat_post') }}', { 'message': $("#chatMessage").val() });
    $("#chatMessage").val('');
}
function updateChat()
{
    if (this.timer)
        clearTimeout(this.timer);

    $.post('{{ path('cunningsoft_chat_list') }}', function(data) {
        $('#chat').html(data);
    });
    this.timer = setTimeout('updateChat()', {{ updateInterval }});
}
updateChat();
</script>

Switch back to SetTimeout, but make the timeout clear on function call; This allows updateChat to be called independently wihtout setting up multiple timeouts
Switch back to SetTimeout, but make the timeout clear on function call; This allows updateChat to be called independently wihtout setting up multiple timeouts
