Making Ajax more powerful !

Making Ajax more powerful !

Postby psindia » Mon May 19, 2008 6:23 pm

Implementing Ajax in a page means implement more notifications in your page. An Ajax call is asynchronous. So when the server is down and an ajax call is made then the whole application will not respond at all. Users may think our application as dump. There are two remedies for the above problem.

  1. Use Pre Defined Ajax Libraries which handles timeout feature

  2 . Use Timeout Feature in your current code ( less effort )



CODE

var gotResponse=0;
var atimer;
function initAjaxCall()
{
if(!gotResponse) // Check whether the reponse has reached at this moment ..
{
alert(" Server not responding at this time .. Please try again latter ");
}
}

function makeAjaxCall()
{
atimer=setTimeout("initAjaxCall()",45000);  // 45 Seconds Delay .. You can adjust this ...
ajaxCall();  // Ajax call logic will be coded in this function
}

function ajaxResponse()
{
gotResponse=1;
// Got the data in the variable data
clearTimeout(atimer);

}
}
-- Site Admin --
tenthstone.com
User avatar
psindia
Administrator
Administrator
 
Posts: 42
Joined: Sun Oct 07, 2007 4:29 pm

Return to Ajax/Javascript

Who is online

Users browsing this forum: No registered users and 1 guest

cron