$(window).load()里面有ajax

I'm trying to retrieve all the data inside the database when the page is loaded but when I try to click the refresh button nothing was returned, do you have any idea why? Here is my code:

      $(window).load(function (){
        $.ajax({                
            url: 'get.php',
            dataType: 'json',
            success: function (data){
               $.each(data, function(i,item) {
                 $('#info').append("<p> you are:"+data[i].username+"</p> <p> your  message  is:"+data[i].msg);
               })
             }
        });


      });

New answer posted here.

Change your php code as below

if(isset($_POST['username']) && isset($_POST['msg'])){
  $username = $_POST['username'];

  $msg = $_POST['msg'];
}

seems like the ajax is not returning before the function gets executed.

Edit:

   $(window).load(function (){
      $.ajax({                
        url: 'get.php',
        dataType: 'json',
        type: 'POST', //u missed this line.
        success: function (data){
          var data_new = jQuery.parseJSON(data);     
          $.each(data_new, function(i, item) {
           $('#info').append("<p> you are:" + data_new.username +"</p> <p> your  message   is:"+data_new.msg);
           });

         }
    });


  });