0

how to make visible this var (rec_count) out of ajax scope? I can't understand this about ajax scope. thanks!

function showImage(str){        
    $.ajax({                                 
        url:            'getimg.php',
        type:       "GET",
        data:           "q="+str,
        dataType:   'json',
        success:    function(data){
            rec_count = data.count;
            console.log('inside: ' + rec_count)
        }
    });
}

$( document ).ready(function(){
    $('body').click(function(){
        showImage(4);
        console.log('outside: ' + rec_count)
    });
});
Stefano Vollono
  • 103
  • 1
  • 9

0 Answers0