1

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>

As you can see value of Random is undefined. How can I store the value in variable Random that returned by a generate_code function?

shah rushabh
  • 155
  • 1
  • 1
  • 8

0 Answers0