I want to create a variable inside ajax and use it in several other places, this only works when I use async:false
and I know this is no longer recommended, how to do this in a way correct?
follow the codes below:
JAVASCRIPT
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.js"></script><scripttype="text/javascript">
$(document).ready(function(e) {
// <![CDATA[
$.ajax({
url: 'lista_empresas.txt',
//async:false,
cache: false,
dataType:"json",
success: function(retorno) {
empresa = retorno['empresa']
$('body').append(empresa)
}
});
$('body').append('Minha empresa: ' + empresa)
});
// ]]>
</script>
JSON
{"company": "ATR Brasil", "branch_activity": "transports"}