I have a problem with this javascript function. What I'm trying to do is, finding a specific "Material Description" using ajax call. When I try to console.log the ajax function, the data is showed up. But when I'm setting to an array, it won't set the array value and skipped. Using "async: false" give me this warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience.
without async will give me undefined result.
$('#iBarcode').keypress(function (keyPressed) {
            if (keyPressed.which == 13) {
                var barcode = $('#iBarcode').val()
                var splitted = new Array()
                var arrayCnt = -1;
                for (var i = 0; i < barcode.length; i++) {
                    var flagStart;
                    if (barcode.charAt(i) == ')') {
                        flagStart = true
                        i += 1
                        arrayCnt += 1
                        splitted[arrayCnt] = ''
                    }
                    if (barcode.charAt(i) == ('(')) {
                        flagStart = false
                    }
                    if (flagStart == true) {
                        splitted[arrayCnt] = splitted[arrayCnt] + barcode.charAt(i)
                    }
                }
                console.log(setMatDesc(splitted[0])) //value showed here
                splitted[arrayCnt + 1] = setMatDesc(splitted[0]) //value not showed here and skipped?
                splitted[arrayCnt + 1] = currentDate
                $('#iBarcode').val('').focus
                console.log(splitted)
            }
        })
        function setMatDesc(MatID) {
            var result
            $.ajax({
                url: '@Url.Action("Get_MatDesc")',
                type: 'GET',
                async: false,
                data: { MatID: MatID },
                success: function (data) {
                    result=data
                },
                error: function (xhr) {
                    alert('error');
                }
            })
            return result
        }
I would appreciate the help, thanks.
 
    