I have this function to load data into #container, after clicking on the li.
HTML
<li onclick="$(document).ShowPosts(4)"></li>
<div class="more">[show posts]</div>
   <div id="container"></div>
JQUERY
jQuery.fn.ShowPosts = function(id_user) {
 var total_posts=999999999;
  $.ajax({
     type: 'POST',
     url: "total_posts.php",
     data: {
       'id_user': id_user
     },
     success: function(data) {
       var total_posts = data;
     });
    //load first group      
    $("#container").load(url_load,{id_user':id_user}, 
   function(){ alert(total_posts); /*shows up 9999999;*/
  });                
   $(".more").on('click', function(e) {
       alert(total_posts); /*shows up retrieved by ajax - correct;*/
     }
   });
}
PROBLEM
The problem is that after the first load .load(), within the load() function(){} the alert shows up total_posts as 9999999 (predefined value) when would have to be the retrieved by ajax total_posts.php
but in the .on() when clicking on .more  the alert shows up correctly the value of total_posts.
Why does an alert shows up incorrect and correct values within the main function?
 
    