Test Case Boilerplate
Fork this way...
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>WebPage has loaded, Ajax request will be sent periodically every 1.5 sec..</p>
</body>
</html>
JavaScript
//Timeout is set based on the request length
var ajax_timeout = 15000;
//Ajax object defined globally to prevent the IE8 GC from clearing this object. This creates error in jquery when request timeout happens ('jqXHR' is undefined, Line: 6819).
var jqxhr_obj = null;
function cyclicFetchAsync(ajaxData)
{
var data;
var status;
var xmlhttp_obj;
var error_obj;
var ajax_settings;
jqxhr_obj = $.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,
success: function (data, status, xmlhttp_obj)
{
$(xmlhttp_obj.responseText).appendTo("body");
//Re-initialize the objects
data = null;
status = null;
xmlhttp_obj.onreadystatechange = null;
xmlhttp_obj.abort = null;
xmlhttp_obj = null;
jqxhr_obj = null;
},
error: function (xmlhttp_obj, status, error_obj)
{
//Ajax request retry - 3 retries
//Throw exception on retries completion
//ajax_error_handle(xmlhttp_obj, status, error_obj);
//Re-initialize the objects
status = null;
xmlhttp_obj.onreadystatechange = null;
xmlhttp_obj.abort = null;
xmlhttp_obj = null;
error_obj = null;
jqxhr_obj = null;
}
});
}
function PeriodicTimerHandler()
{
//send periodic requests based on the current screen
cyclicFetchAsync({
html: "<p>Response data from server - text</p>",
delay: 2 //delays echo response 2 seconds
});
}
//The below statements not working in fiddle
//var...