Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function should wait till ajax request completes

    Hi,
    i am using following code
    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

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    The asynch call does not work like that. You need to call the second part of your function from the sucess function call.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 );
    Last edited by Ducatti; 11-18-2008 at 04:02 AM. Reason: Adding which version of Ajax I'm using


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •