Occasionally, when I click a button on my web application, I do not receive any response. This button triggers an ajax call. I suspect that the lack of response may be due to heavy web traffic causing it to time out or something similar. Is there a maximum wait time for ajax responses from the server? Is there a way to track and log this behavior? Below is the ajax code I am currently using.
var Ajax = {
createAjaxObject: function()
{
var request;
try
{
request = new XMLHttpRequest();
}
catch(error)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(error)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(error)
{
request = false;
}
}
}
return request;
},
useAjaxObject: function( path, param, ajax_func, html_div )
{
var object = new Ajax.createAjaxObject();
object.open( "POST", path, true );
object.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
object.setRequestHeader( "Content-length", param.length );
object.setRequestHeader( "Connection", "close" );
object.onreadystatechange = function()
{
if( this.readyState === 4 )
{
if( this.status === 200 )
{
ajax_func( this.responseText, html_div );
}
else
{
Ajax.repeatUseAjaxObject( path, param, ajax_func, html_div );
return false;
}
}
};
object.send( param );
return true;
},
repeatUseAjaxObject: function( path, param, ajax_func, html_div )
{
var state = false,
count = 1;
while(state === false && count <= 5)
{
state = Ajax.useAjaxObject( path, param, ajax_func, html_div );
if( count !== 1 )
{
alert( 'Ajax Object Use Failed ');
}
count++;
}
}