...

View Full Version : function should wait till ajax request completes



kummu4help
11-17-2008, 01:15 PM
Hi,
i am using following code


function callajax()
{
var handleSubmit = function() //this function is related to yahooYUI.so i want this should be like this.
{
var temp=do_login();
alert(temp);
};
}

function do_login()
{
var retValue=false;
AjaxRequest.submit
(
fobj,//fobj is a reference to my form. don't worry abt it
{
"onSuccess":function(req)
{
var retval = CB_do_login(req);
retValue=ret;
//alert(ret+"\n"+temp);
},
"onError":function(req){ CB_error_do_login(req);},
"onTimeout":function(req){ CB_timeout_do_login(req);}
}
);

return retValue;
}



i am using AjaxRequest.js library for processing ajax calls.... so i need help in that point of view

now what i want to do is
i have a callajax() function. with in this function i will call do_login() function. this do_login() handles an ajaxrequest and returns the responsetext.

now i want to do some validation on this responsetext(in case of onsuccess).
so i am trying to return value to callajax() function for onSuccess case in ajaxrequest.submit();

that is(onsuccess response) supposed to be some string( but not true or false).
but i am always getting false in ajaxcall() function.
i know the do_login() function is returning false before ajaxrequest completes

so i want to stop this and make do_login wait until ajaxrequest completes and then i want to return it's response to callajax() function

can anyone help me

A1ien51
11-18-2008, 03:12 AM
The asynch call does not work like that. You need to call the second part of your function from the sucess function call.

Eric

Ducatti
11-18-2008, 03:58 AM
The following works for me using Dojo:

function getAXAH(url,elementContainer){
document.getElementById(elementContainer).innerHTML = '<blink class="redtxt">Loading...<\/blink>';
var theHttpRequest = getNewHttpObject();
theHttpRequest.onreadystatechange = function() {processAXAH(elementContainer);};
theHttpRequest.open("GET", url);
theHttpRequest.send(false);
function processAXAH(elementContainer){
if (theHttpRequest.readyState == 4) {
if (theHttpRequest.status == 200) {
var retval = theHttpRequest.responseText;
callajax(retval );



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum