title: How to save AJAX data to use later?
body: <pre><code>  $.ajax({
               url:"&lt;?php echo site_url('proposal/getContact');?&gt;/"+client,
               type: 'GET',
               dataType: 'json',
               success:function(data) {
               //On succes the data is returned from the url and used accordingly.
                  htm='&lt;option value=""&gt;Select&lt;/option&gt;';
                  for(i=0;i&lt;data.length;i++){
                      htm +='&lt;option value="'+data[i].Id+'"&gt;'+data[i].Name+'&lt;/option&gt;';
                  }
                   $('select[id="ProjectContact"]').html(htm);
                }
            });
  </code></pre>
  
  <p>I want to use the variable data later so that when i select the project contact i have to deal with the same data.
  I have tried using</p>
  
  <pre><code>$('select[id="ProjectContact"]').change(function() {
      var contact=$('select[id="ProjectContact"]').val();
                   htm='&lt;div class="span2 text-right"&gt; &lt;img class="img-rounded"&gt; &lt;/div&gt;';
                   htm+='&lt;div class="span4"&gt;';
                   htm+='&lt;strong&gt;';
                   for(i=0;i&lt;data.length;i++){
                      if(data[i].Id != contact)
                          continue;
                      htm+=data[i].Name+
                      "&lt;/strong&gt;,&lt;br/&gt;"+data[i].Designation+",  &lt;br/&gt;"+
                      data[i].PhoneNumber+",&lt;br /&gt;";
                      htm+=data[i].Email+",&lt;br/&gt;"+
                      data[i].FacebookUrl+",&lt;br /&gt;"+data[i].TwitterUrl+",&lt;br/&gt;"+
                      data[i].LinkedinUrl;  
                      htm+='&lt;/div&gt;';
                   }
                   $("#ContactDetails").html(htm); 
  
   });
  </code></pre>
  
  <p>says data is not recognised.
  Thank You.</p>