简体   繁体   English

加载内容AJAX Jquery-需要如何向加载的页面发送数据?

[英]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. 我的页面上有一些需要通过Ajax加载的内容。 The page that I want to load is requesting some php variables I have stored on the main page. 我要加载的页面正在请求一些已存储在主页上的php变量。

How can I send these variables to the page then load the page via ajax? 如何将这些变量发送到页面,然后通过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? 有没有更好,更有效的方法来做到这一点?

// 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. 此代码可能使您有想法在您的方案中实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM