Test Case Boilerplate

Fork this way...

HTML

<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
        <p>WebPage has loaded, requests pending...</p>
    </body>
</html>

JavaScript

//Timeout is set based on the request length
var ajax_timeout = 10000;
var requests = 0;

function cyclicFetchAsync(ajaxData)
{
    requests++;
    $.ajax(
    {
        url: "/echo/html/",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        global: false,
        type: 'POST',
        data: ajaxData,
        dateType: "text",
        async: true,
        timeout: ajax_timeout,
        cache: false,
        complete: function(){ requests--; },
        success: function (data, status, xmlhttp_obj)
        {
            $(xmlhttp_obj.responseText).appendTo("body");
        },
        error: function (xmlhttp_obj, status, error_obj)
        {          
            $("<p>error "+ status + " - "+requests+" requests active</p>").appendTo("body");            
        }
    });
}


setInterval(function()
{
    //send periodic requests based on the current screen
    cyclicFetchAsync({
        html: "<p>Response data from server - "+requests+" active requests</p>",
        delay: 8
    });
}, 1000);