Here's the basic idea with my code. I added comments where I'm having issues. Basically, I need to get the value from a select (no problem) and pass this into an AJAX query to be used in both the query (no problem) and in the success (the issue).
var picked_dis;
$(document).ready(function() {
$('#disease').change(function(event) {
picked_dis = $('#disease').val();
$.ajax({
url: 'https://something.cartodb.com/api/v2/sql?q=SELECT territory,'+picked_dis+' from testnumbers_merge',
//variable works in the above
type: 'GET',
success: function(data) {
var ticks6 = data.rows.map(function(ele) {
return ele.picked_dis; //this is where I want the variable to work but doesn't
});
console.log(picked_dis);//this returns the correct variable
ticks6.sort(function(a, b) {
return a - b
});
});
});
});