当我调用这个函数时,我收到了我想要的正确数组,但是一旦我尝试返回它,控制台就会告诉我“选项”是未定义的。有任何想法吗?
function getOptionsJSON(Ordernumber) {
$.getJSON(window.location.pathname+'/ajaxRequest?ordernumber='+Ordernumber+'&'+Math.round(new Date().getTime()), function(data) {
if(data['articleID']) {
options = data['values_label_array'];
console.log(options) // returns {"1":"Option 1","2":"Option 2"}
}
});
console.log(options) // returns Undefined
return options;
}
function selectOptions(){
var options = getOptionsJSON($(row).find('.ordernumber').val());
console.log(options) // returns Undefined
}
这是在 AjaxREquestAction 中调用的 PHP 函数:
$returnData["values_label_array"] = json_encode($this->getOptionsAction($ordernumber));