如何将ajax结果用作我可以在页面中随处打印的变量

Here is my ajax code:

$("#to").change(function(){
  $.ajax({ 
  type: "POST",
  url: "<?php echo base_url();?>/index.php/sales/getPrice",             
  dataType: "html",       
  data: {'from' : $('#from').val() , to: $('#to').val()},    
  success: function(response){                
  //$(".location").html(response); 
 }
});             
});

I want to use ajax result instead of 40.(below code attached). Any idea? It it's not clear please ask me.

e: {
 price   : 40,
 category: 'Economy'
}
var result = '';

$("#to").change(function(){
  $.ajax({ 
  type: "POST",
  async: false,
  url: "<?php echo base_url();?>/index.php/sales/getPrice",             
  dataType: "html",       
  data: {'from' : $('#from').val() , to: $('#to').val()},    
  success: function(response){                
      result = response;
 }
}); 
});

Now use that result where you want:

e: {
     price   : result,
     category: 'Economy'
  }

You want to use the data the ajax call returned? So you can use it in the success part:

$("#to").change(function(){
  $.ajax({ 
  type: "POST",
  url: "<?php echo base_url();?>/index.php/sales/getPrice",             
  dataType: "html",       
  data: {'from' : $('#from').val() , to: $('#to').val()},    
  success: function(response){                
     alert(respone.price);
     console.log(response);
 }
});             
});

Use console.log(response); in the success function, to get the data in the developer console of your browser.