Possible Duplicate:
Why is this function returning “undefined”?
Why in following code return is undefined in case return should is true? what do i do?
<input type="text" value="" class="ticket_code">
function ticket_check() {
    var val = 'ticket_code=' + $('.ticket_code').val();
    var input_val = $('.ticket_code').val();
    $.ajax({
        type: "POST",
        url: 'get_ticket_code',
        data: val,
        cache: false,
        success: function (data) {
            var result = true;
            if (data != 0) {
                $('div').empty().hide().fadeIn('slow').append(data + '<input name="name_ticket_code" value="' + data + '" style="display: none;">');
            } else {
                if (input_val) {
                    $('div').fadeOut('slow', function () {
                        $(this).empty();
                    })
                    result = false;
                }
            }
            return result
        }
    });
}
alert(ticket_check());
 
     
     
     
     
    