我在函数内部声明了一个变量,并在变量函数内的另一个函数内再次修改它。为什么返回变量上传的值会重置或重新初始化?
var upload = [];
$upload.upload({
url: '/ibsapp/app/app/api/libs/upload.php',
file: file[0],
data: fileLocation,
}).success(function (data, status, headers, config) {
// add publication data
AppService.insertService('publication', publication).then(function(response){
// If unsuccessful in inserting data in the database, delete the files that are uploaded.
if(response['status'] === "error"){
$upload.upload({
url: '/ibsapp/app/app/api/dbHelper/delete.php',
data: fileLocation + '/' + file[0].name,
});
/* upload value is now the response */
upload = response;
});
}
});
/* When I log here, the value of upload is reset to [] */
console.log(upload);
return upload;