views:

28

answers:

1

I have some content on my page that I require to be loaded via ajax. The page that I want to load is requesting some php variables I have stored on the main page.

How can I send these variables to the page then load the page via ajax???

Code so far:

$('#microblogposts').load('posts.php', {postmessage="+ postmessage +"& from_user="+ from_user +"& from_username="+ from_username  });

Is there a better more efficient way to do this???

+1  A: 

// Main Page say main.php

<?php  
      $postmessage = "msg"; 
      $from_user = "ayaz" 
 ?>
 <script>
       var pm  = <?php echo $postmessage; ?>
       var fu = <?php echo $from_user; ?>
       $(function(){
            $.post("posts.php",{postmessage: pm, from_user: fu}, function(data){
                $('#microblogposts').html(data):    
            });
       });
 </script>

This code might give you idea to implement in your scenario.

Ayaz Alavi