On Nov 17, 12:13 pm, badgerduke <[EMAIL PROTECTED]> wrote: > Hello: > > I've been trying to use Ajax.Request(). The following is my code: > > function retrieveProjectPermissions(stateDataID, projectID) { > > new Ajax.Request('/gallupFaith/me25/ > ProjectPermissionsAjaxAction.action', > { > method:'get', > parameters: {statedataid: stateDataID, projectid: projectID}, > onSuccess: function(transport){ > var responsePP = transport.responseText; > alert("Success! \n\n" + responsePP); > if (agentPP.indexOf('msie') != -1) {
Is this based on UA sniffing? If yes, then it's not a good idea. How do `msPopulatePP` and its counterpart differ? > var permissionArray = msPopulatePP(responsePP); > return permissionsArray; > } > else if (agentPP.indexOf('mozilla') != -1) { Same here : ) > var permissionArray = nonMSPopulatePP(responsePP); > return permissionsArray; > } > }, > onFailure: function(){ alert('Something went wrong...') } > }); > > } > > I am trying to return the variable permissionsArray to the caller of > retrieveProjectPermissions(). I can't use global variables because > there is some timing issue . . . the variables always end up undefined > after I set them. How can I return permissionsArray? Ajax.Request is asynchronous. `onSuccess` is called much later after `retrieveProjectPermissions` exits (when client receives response from the server and that response is "successful"). Use `onSuccess` to retrieve and then start using that variable; E.g. you can pass some kind of callback to enclosing function and invoke that callback function passing it variable in question: function retrieveProjectPermissions(stateDataID, projectID, callback) { // ... // initialize Ajax.Request // ... onSuccess: function(response) { // get permissionArray callback(permissionArray); } }; and then call it like so: retrieveProjectPermissions(1, 23, function(arr) { // do something with `arr` }); > > Thanks > Eric- -- kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---