我有一个简单的Ajax功能JS的Ajax功能不设置变量值
function get_country(request_term) {
var country_list = '';
$.ajax({
url : "activity/get_country",
type : "POST",
cache : false,
data : {
request_term : request_term
},
success : function(data) {
if(data != '') {
country_list = $.parseJSON(data);
alert(country_list); ----> Got value here
}
}
});
alert(country_list); ----> Not getting value here
return country_list;
}
的问题是,我得到的成功,函数的数据,但无法从main函数返回。
的可能重复[如何返回Ajax响应文本?](http://stackoverflow.com/questions/1225667/how-to-return -ajax-response-text) – Quentin