【发布时间】:2015-09-01 08:41:45
【问题描述】:
我正在尝试返回一个全局变量并在数组中设置一个对象。
谁能解释我在检索全局变量outPutArray 时做错了什么?当我尝试返回它时它变得未定义。
var outPutArray = {};
var goAjax = function(data, filePath) {
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: filePath, //Relative or absolute path to response.php file
data: data,
success: function(data) {
for (x in data) {
outPutArray[x] = data[x];
}
//logs the the wanted value
console.log('inside ' + outPutArray['json']);
}
});
};
goAjax.prototype.getValue = function() {
console.log('outside ' + outPutArray['json']);
//logs undefined ??
};
【问题讨论】:
-
你确定对象数据(及其replicateoutPutArray)有一个名为“json”的属性吗?
标签: javascript object return