1

I have this AJAX call that receives data from the server. The only solution I've found is to make async: false to get the data outside the function. But it is deprecated. Is there any better option to get the variable out the function? Any suggestion would be appreciated.

 var suggest =[];
    $.ajax({
        type: "POST",
        url: //LINK,
        async: false,
        data: {
            "dataA": string
        },
        cache: false,
        success: function(data) {
            suggest = JSON.parse(data);
        }
    });

I am using the variable i'm getting from the call many times is there any better way to do it?

    for (var i = suggest.length - 1; i >= 0; i--) { 

        for (var j = 0; j < arrString.length; j++) {
            if (suggest[i] === arrString[j]) {
                suggest.splice(i, 1);
            }
        }
    }

    var obj = {};

    var suggestKey = "Suggesting";
    var suggestArray = [];
        obj[suggestKey] = suggest;
        suggestArray.push(obj);
Best Jeanist
  • 1,109
  • 4
  • 14
  • 34

0 Answers0