Javascript-PHP变量传递

时间:2012-12-10 08:55:11

标签: php javascript uploadify

我有一个php文件,其中从另一个PHP文件中获取一个变量。现在我想将此变量传递给另一个在Javascript中给出的PHP文件。我怎样才能做到这一点?以下是Uploadify的代码

<head>


<script type="text/javascript" src="uploadifyit/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="uploadifyit/swfobject.js"></script>
<script type="text/javascript" src="uploadifyit/jquery.uploadify.v2.1.4.min.js">     
<script type="text/javascript">

$(document).ready(function() {

//alert('I am ready to use uploadify!');
$("#file_upload").uploadify({
    'uploader': 'uploadifyit/uploadify.swf',
    'script': 'uploadifyit/uploadify.php',
    'cancelImg': 'uploadifyit/cancel.png',
    'folder': 'uploads',
    'auto': false, // use for auto upload
    'multi': true,
    'queueSizeLimit': 200,
    'onQueueFull': function(event, queueSizeLimit) {
        alert(" You can upload " +    queueSizeLimit + " files at once");
        return false;
    },
    'onComplete': function(event, ID, fileObj, response, data) {
        // you can use here jQuery AJAX method to send info at server-side.
        $.post("insert.php", { name: fileObj.name},   function(info) {
            alert(info); // alert UPLOADED FILE NAME
        });
    }
     });

        });

       </script>

      </head>

      <body>
      <?php
      $tabname=$_GET['tabname'];
      ?>

      <form id="form1" name="form1" action="">
      <input type="file" id="file_upload" name="file_upload" /><br />
       <a href="javascript:$('#file_upload').uploadifyUpload();">Upload File</a>
      </form>
      </body>
      </html>

参见本节,$ tabname是我想在insert.php中使用的变量。我需要将这个$ tabname传递给insert.php并在其中使用它...提前谢谢

2 个答案:

答案 0 :(得分:1)

您可以使用脚本数据标记:

'scriptData'     :{
    'variable1': '<?php echo $_GET["variable1"]; ?>',
    'variable2': '<?php echo $_GET["variable2"]; ?>'
},

或者,为什么不将变量存储在$_COOKIE$_SESSION变量中?您可以在其他脚本中访问这些变量,而无需传递任何内容。

答案 1 :(得分:0)

将您的帖子更改为:

$.post("insert.php?tabname="<?=$_GET['tabname'];?>, { name: fileObj.name},   function(info)