Loading content AJAX Jquery - Need to send data to loaded page how?
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 +"& fr开发者_运维问答om_user: "+ from_user +"& from_username: "+ from_username });
Is there a better more efficient way to do this?
// 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.
精彩评论