title: How can I use $.ajax success data in somewhere else?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2844832/return-from-jquery-ajax-call">return from jquery ajax call</a><br>
    <a href="https://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success">jQuery: Return data after ajax call success</a>  </p>
  </blockquote>
  
  
  
  <pre><code>        $.ajax({
              url:"list.php",
              dataType: "json",
              success: function(resp){
                  for(var i=0;i&lt;resp.length;i++){
                      $('#goods_list').append(
                        "&lt;h3&gt;" + resp[i]["name"] + "&lt;/h3&gt;"
                        +
                        "&lt;div&gt;Price： NT$" + resp[i]["price"] + "&lt;br /&gt;"
                        +
                        resp[i]["description"]
                        +
                        "&lt;hr /&gt; &lt;a href=# alt='"+ resp[i]["sn"]+ "' class='add_to_cart'&gt;Add&lt;/a&gt; | More"
                        +"&lt;/div&gt;"
                      );
                  }
  
                  var resp2 = resp;
              }
          });
  
          $('body').append(resp2[0]["price"]);
  </code></pre>
  
  <p>And FireBug said:</p>
  
  <pre><code>ReferenceError: resp2 is not defined
  $('body').append(resp2[0]["price"]);
  </code></pre>
  
  <p>How can I use <code>$.ajax</code> success data in somewhere else? (outside the $.ajax function)</p>
  
  <p>The concept is similar to "Global Variables".</p>