syncronous ajax request and variables outside of the request

syncronous ajax request and variables outside of the request

I've built a function that handles my ajax calls. I know it doesn't make much sense in this small test script i built, but i would really like to have this work in this way. I'll explain the script then post it below.

First, i have a function that creates a dialog based on the parameters passed in. I simplified the function for this test to only accept one parameter; an ajax options object. Inside of this function, i am creating a default ajax options object, extending it with the ajax options object passed in, I then initialize the return variable with a string, and make the ajax call. Within the success function of the ajax call, i set the value of the return variable equal to the jquery object. After this ajax call, i alert the return variable. If successful, the return variable should be an object instead of a string.

Temp2.cfm returns:
  1. <div></div>
the script:
  1. $(document).ready(function(){
  2.     var sendAjaxRequest = function(ajaxParam) {
  3.         var defaultAjax = {
  4.             method:"GET",
  5.             async:false,
  6.             success:function(data){
  7.                 returnData = data;
  8.             }
  9.         };
  10.         $.extend(defaultAjax,ajaxParam);
  11.         var returnData = "default";
  12.         $.ajax(defaultAjax);
  13.         alert(returnData);
  14.     }   
  15.     $('a.clicker').click(function(){
  16.         var customAjaxObj = {
  17.             url: "temp2.cfm",
  18.             success: function(data){
  19.                 returnData = $(data).attr('name','customName');
  20.             }
  21.         }
  22.         sendAjaxRequest(customAjaxObj);
  23.     });
  24. });
Edit: i forgot to mention what was happening. the alert always returns "default" rather than the object.

-- Kevin

------------------------------------------------
http://www.tentonaxe.com