Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How to handle te concurrent Ajax request?
You can process more than one AJAX request process at a single time with using JavaScript. In proper post processing of code it is recommended that you use JavaScript Closures.
I have given you example that shows an we can abstract XMLHttpRequest object by a JavaScript object called AJAXInteraction. 
When you pass argument in the URL to call and the function to call when completing the processing.

function AJAXInteraction(url, callback)
{
   var req = init();
   req.onreadystatechange = processRequest;
   function init() 
{
if (window.XMLHttpRequest) 
{
   return new XMLHttpRequest();
} 
else if (window.ActiveXObject) 
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function processRequest () 
{
   if (req.readyState == 4) 
{
   if (req.status == 200) {
if (callback) callback(req.responseXML);
}
}
}
this.doGet = function() 
{
   req.open("GET", url, true);
   req.send(null);
}
this.doPost = function(body) 
{
   req.open("POST", url, true);
   req.setRequestHeader("Content-Type", "
   application/x-www-form-urlencoded");
   req.send(body);
}
}
function makeRequest() 
{
   var ai = new AJAXInteraction("processme",
   function() { alert("Post Processing is going  
   on");});
   ai.doGet();
}
 Above we use function to makeRequest() to create an AJAXInteraction with a URL to of "processme" and their is an inline function which is use to show alert dialog with the message "Post Processing is going on". 
When we called ai.doGet() function than the Ajax interaction is initiated and when server-side component mapped to the URL "processme" returns a document and we passed them to the callback function that was specified when the Ajax Interaction was created.We use callback function that is associated with a specific AJAX interaction.When we creating multiple closure objects in that make XmlHttpRequests as to there is a limited number of sockets that are used to make requests at any given time.We can made concurrently with the limited number of requests. In internet explorer at any given time allows for two concurrent Ajax requests. Generally,In case of other browsers we can allow more than three and five requests. 
 Keep in mind when you making multiple AJAX calls from the client than their is no guaranty to return rspose at given order.
Posted By: Name:Rajesh Kr URL: How to handle te concurrent Ajax request?