jQuery / Colorbox - 在弹出窗口中将一个java变量传递给PHP变量

时间:2015-03-10 11:12:18

标签: javascript php jquery mysql ajax

请您告诉我如何获取java变量" data_id" PHP变量" $ gal_id"我无法将java变量的值传递给PHP变量,所以如果找到解决方案,请告诉我

JS IN Head

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/jquery.colorbox.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Examples of how to assign the Colorbox event to elements

$(".inline").colorbox({inline:true, width:"70%", height:"500px;"});
});
</script>

HTML

<li><a class='inline' href="#inline_content" data-id="1">ABC</a></li>
<li><a class='inline' href="#inline_content" data-id="2">DEF</a></li>
<li><a class='inline' href="#inline_content" data-id="3">XYZ</a></li>

POPUP Box

<script type="text/javascript">
$('.inline').click(function(){
   var data_id = $(this).data('id');
   $('#idvalue').html(""+data_id);
});
</script>

<div style='display:none'>
    <div id='inline_content'>
    <span id="idvalue"></span><!--we'll get here data_id value of clicked list in output -->
    <?php
    $gal_id = ""; // Will you please please tell me how to get java variable "data_id" value here from above js
    $check = mysql_query("select * from img where id = '$gal_id'");
    while ($run = mysql_fetch_array($check)){

    .
    .
    .
    }?>

</div>
</div>

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你就不能这样做。 您可以查看其他可以帮助您的问题: How to pass JavaScript variables to PHP?

答案 1 :(得分:0)

尝试此编辑...我已将ajax与您的代码集成

<script type="text/javascript">
$('.inline').click(function(){
   var data_id = $(this).data('id');
   $('#idvalue').html(""+data_id);
 $.ajax({
         type: "GET",
         url: "ajax.php?gal_id="+data_id,
         success: function(data) {
             $('#images').html(data);
         }
     }); 
});
</script>

<div style='display:none'>
    <div id='inline_content'>
    <span id="idvalue"></span>
<span id="images"></span>


</div>
</div>

创建新文件ajax.php

并将此代码放在那里......

<?php
//whatever content you will echo here will be send to the main page and put to #images span tag...
//put your connection string here.. to connect the database
        $gal_id = $_GET['gal_id']; 
        $check = mysql_query("select * from img where id = '$gal_id'");
        while ($run = mysql_fetch_array($check)){

        .
        .
        .
        }?>