PDA

View Full Version : synchronous connection



olimpia
25 Apr 2007, 4:04 AM
I am using the code below to do a research in the database


function ValidaPage(oForm){
var IsValid = true;
var oFormLength = oForm.elements.length;
for(var i=0; i<=oFormLength-1; i++ ) {
var oSrcElement = oForm.elements[i];
var postData="field=" + oSrcElement.id;
var hcallback={success:function onSuccess(resp){if (resp.responseText == "false"){IsValid=false;}}};
YAHOO.util.Connect.asyncRequest('POST', "valida.ashx", hcallback, postData);
}
if (IsValid)
return true;
else
return false;
}
}

The connection executed of way asynchronous. I have to await the result of the research in the server to continue the for, as I should do to connect of way synchronous

haibijon
25 Apr 2007, 5:09 AM
Synchronous broswer requests are typically bad practice. A synchronous request halts the browser completely while waiting for the result. Typically if using a synchronous request, basic functionality of the browser, like clicking the back button, scrolling, or even just visiting your home page or brining up preferences, becomes disabled, leaving the user with a (seemingly) frozen application. This article (http://web.kellegous.com/ecrits/001096) highlights some really good points on using asynchronous requests and not asynchronous.

In your case I believe it would be better to send an asynchronous request and display a loading mask until the data is retrieved...