I would like to make fileContent variable available outside of $.ajax code. var fileContent = ""; $.ajax({ method: "POST", url: "php/somefile.php", data: {"nazwaProduktu": "nazwa produktu"}, }).done(function( data ) { var result = $.parseJSON(data); if (result!== null){ var len = result.length; for(var i=0; i<len; i++){ fileContent=fileContent+result[i].nazwa+";"; fileContent=fileContent+(result[i].komentarz)+"\n"; } } } ); console.log(fileContent); //aqui veo fileContent vacio! Necesito tenerlo actualizado por el código anterior.
¿Puede por favor aconsejarme cómo puedo hacer esto?