var Random = generate_code();
console.log(Random);
function generate_code(){
var Random = Math.floor(Math.random() * (999999999999 - 100000000000 + 1)) + 100000000000;
check_barcode(Random);
}
function check_barcode(code) {
var data = {
Code: code,
}
var formsubmission = 'https://www.vsss.co.in/Admin/index.php/Ajax/check_barcode';
return $.ajax({
method: "POST",
url: formsubmission,
data: data,
success: function(response) {
var data = JSON.parse(response);
if (data['Existing'] >= 1) {
generate_code();
} else if (data['Disconnected'] >= 1) {
generate_code();
} else {
return code;
}
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
正如您所看到的,Random的值未定义。如何将值存储在generate_code函数返回的变量Random中?