title: jQuery AJAX HAndling problem
body: <p>I am trying to create a JavaScript object that will deal with all of my ajax calls instead of making several different ajax handlers have one that does the job for all.</p>
  
  <p>So here's what I have so far </p>
  
  <p>My PHP files that are going to be called within my AJAX Handler are placed in a directory called ajax, the directories within that are named to relate to the pages e.g. the jobs page has its own directory and so on. within these directories I have placed the page relevant PHP files.</p>
  
  <p>so now to my ajax Handler object code:   </p>
  
  <pre><code>function ajaxHandler(pageName,functionCall){
  this.pageName       = pageName;
  this.functionCall   = functionCall;
  
  // set functions
  this.getPage = getPage;
  this.setPage = setPage;
  this.getFunctionCall = getFunctionCall;
  this.setFunctionCall = setFunctionCall;
  this.performAjaxCall = performAjaxCall;
  }
  // accessor for current page
  function getPage(){
      return this.pageName;
  }
  
  // accessor for setting the current page
  function setPage(page){
      this.pageName = page;
  }
  
  // accessor for retrieving the current functionCall
  function getFunctionCall(){
      return this.functionCall;
  }
  
  // accessor for setting the current function call
  function setFunctionCall(func){
      this.functionCall = func;
  }
  
  // perform the loaded ajax call
  // DATA : must be in the form of JSON
  function performAjaxCall(data){
      $.ajax({
         type     : 'POST',
         url      : '/ajax/'+ this.pageName + '/' + this.functionCall + '.php',
         dataType : 'json',
         data     : data,
         success  : function(data){
            return data;
         },
         error    : function(xhr, ajaxOptions, thrownError){
            return {"error":true,"msg":thrownError};
         }
      })
   }
  </code></pre>
  
  <p>so with this file called and working fine, apart from when performAjaxCall is called the ajax works perfectly but the data being returned is being seen as undefined I will show you an example</p>
  
  <pre><code>function getActiveJobs(initPage){
     var ajh = new ajaxHandler('jobs','getActiveJobs');
     var req = {'page' : 1};
     var data = ajh.performAjaxCall(req);
     alert(data.error);
  }
  </code></pre>
  
  <p>The alert returns undefined, I suspect it is because the JavaScript is not waiting for the data to be returned and as such data is not yet defined, but I am unsure I thought I would ask here before leading myself down a blind alley.</p>