1

我有一个 Jquery 帖子,我想传递一些我在 php 中的变量值。

这是jQuery:

<script type="text/javascript">
      $("#button1").submit(function(event) {
         $.post('file.php?do=getLastFile',null,function(attachment){
           //
        },'json');

        });

  </script> 

我有一个 php 变量 ... myPhpVariable 我想添加到:

file.php?do=getLastFile

所以是这样的:

file.php?do=getLastFile&somevar=$myPhpVariable  

我该怎么做以上?

4

2 回答 2

2

首先将您的 php 变量分配给 JS,然后使用它。

   var phpvar = '<?php echo $myPhpVariable;?>'; //use it like this
   $("#button1").submit(function(event) {
     $.post('file.php?do=getLastFile&somevar='+phpvar,null,function(attachment){
       //
   },'json');

   });
于 2013-10-14T12:35:34.177 回答
0
Value.php

<?php
   $value = 1;

?>


//This would be the page that would use the value you are trying to pass into jquery
<?php

    include('Value.php');


?>


Usevalue.php page
//Then in your javascript you could collect the variable in the Value.php page
<script>
var value = "<?php echo $value; ?>";

$(document).ready(function (){

   //then you can call the value in your jquery here  
});
</script>
于 2013-10-14T13:06:17.400 回答