I have code like this:
var array = [];
$('#next1').on('click', function(){
var dataString='company= '+$(this).closest('.inside').find('select').val();
$.ajax({
//async: false,
type:"POST",
url:"ajax/companyInfo.php",
data: dataString,
success: function(response){
array = response.split("/");
alert(array);
}//end success function
});//end ajax
console.log(array);
it alerts correct array but logs empty array, means that i can't use it after success function.
YES, i have read tons of things regarding this problem (including this: How do I return the response from an asynchronous call?) and making it synchronous solves problem (U see it's commented in code), but everyone say it's very bad to use this method. so I have two questions:
1: why it alerts correct value if case is in sync. I mean it's explained that synchronous waits for response before executing another code and asynchronous doesn't, and that's why it can't catch variables to assign to array. but if it so, how can it alert them?
2:how can i modify code to make it work?