John,

Thanks so much for responding. I did manage to work around the problem, by calling the function with the ajax call first and then the function that uses the return object second. Both ways work, so it's nice to see that if I do something like that again, I could just add an 'async: false' to my ajax call, but I'm guessing that's not the preferred method.

Thanks again!

Chris

John Resig wrote:
To make your call synchronous, try something like this:

if(mode == "edit"){
   var userObj = getActiveUsers();
   // if I dump userObj here...
   dump(userObj); // dump shows that userObj is undefined. :o(
}

function getActiveUsers(){
   return eval("(" + $.ajax({
       type: "post",
       url: "GetActiveUsers.cfm",
       async: false,
       error: function(){
           alert("There was an error...");
       }
   }).responseText + ")");
}

--John

On 1/29/07, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:
Christopher Jordan schrieb:
Hi folks,

I have an ajax call that upon success has a variable 'r' that
contains a JSON encoded string. I eval that string and it becomes an
object (an array of structures, etc.), but when I try returning that
object from the function to the caller, something goes wrong. The caller
says that the value returned is undefined.
[...]
Help! :o(

I'm really confused why this isn't working. I need serious help... asap!
:o( :o(

Wrapping the $.ajax call in a function doesn't make the call
synchronous. Your function returns before the success callback is
executed. You have to restructure your code to work with the success
callback, instead of relying on a return value.

--
Jörn Zaefferer

http://bassistance.de


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/


--
http://cjordan.info

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to