title: How to store ajax JSON object into global variable to be accessed outside the function
body: <p>How do I store ,success function returned data into global variable.</p>
  
  <pre><code>$("form").on("submit", function () {
      var data = {
          "action": "test"
      };
      data = $(this).serialize() + "&amp;" + $.param(data);
      $.ajax({
          type: "POST",
          dataType: "json",
          url: "ajax2.php",
          data: data,
          success: function (data) {
              //How to store the above data into a global variable?
              $("#main_content").slideUp("normal", function () {
                  for (i = 0; i &lt; data.length; i++) {
                      $(".the-return").append("&lt;div class='inside_return'&gt;Name:" 
                              + data[i].name + "&lt;br/&gt;Id:" 
                              + data[i].id + "&lt;br/&gt;Pricing:" 
                              + data[i].rate + "&lt;br/&gt;Postcode:" 
                              + data[i].postcode + "&lt;br/&gt;Reputation:" 
                              + data[i].reputation + "&lt;br/&gt;Review Plus:" 
                              + data[i].plus + "&lt;br/&gt;Review Negative:" 
                              + data[i].neg + "&lt;br/&gt;&lt;h1&gt;Availability&lt;/h1&gt;Week Morning:" 
                              + data[i].weekM + "&lt;br/&gt;Week Afternoon:" 
                              + data[i].weekA + "&lt;br/&gt;Week Evening:" 
                              + data[i].weekE + "&lt;br/&gt;Weekend Morning:" 
                              + data[i].endM + "&lt;br/&gt;Weekend Afternoon:" 
                              + data[i].endA + "&lt;br/&gt;Week Evening:" 
                              + data[i].endE + "&lt;/div&gt;");
                      //alert(data[i].name) 
                  }
              }); //closes #main_content
          }
      });
      return false;
  });
  </code></pre>
  
  <p>This ajax is only performed when the search form is submitted. After the php query returned the result ,I want to enable the user to sort the data of the json object. In order to do this, I need to store the object('data' in this case) to a global variable.It' because I have a function that will make use of this data to perform sorting!</p>