I need to store some data outside ajax call in a variable. So, I am using async: false option in ajax. But it gives me an error:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
See my code below:
var internal_tags = null;
$.ajax({
async: false,
dataType:'json',
contentType:'application/json',
url: '/ajax-search-suggestions',
type: 'GET',
success: function(data) {
asignVariable(data);
}
});
// get internal tags
function asignVariable(data){
internal_tags = data;
}
I need to save ajax success data into internal_tags variable. If I remove the option async: false, data are not saved in variable. So how I can remove the error or how to save ajax success data in the variable which is outside of ajax.
async: falseso that you never ever repeat this mistake again.async: false?