这是我的代码的基本想法。我在问题中添加了评论。基本上,我需要从select(没问题)中获取值,并将其传递给AJAX查询,以便在查询(没问题)和成功(问题)中使用。
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
});
});
});
});