Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);
        }
    });


What I have tried:

I am using the variable i'm getting from the AJAX call many times is there any better way to do call the data from the success function outside?

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);
           }
       }
   }
Posted
Updated 7-Jun-18 18:13pm

1 solution

how about this?
    $.ajax({
        type: "POST",
        url: //LINK,
        async: false,
        data: {
            "dataA": string
        },
        cache: false,
        success: process
    });
function procees(jsondata) {
…
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900