doujiao2443 2015-03-10 11:12
浏览 64
已采纳

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

Will you please please tell me how to get java variable "data_id" value in PHP Variable "$gal_id" i m not able pass the value of java variable into PHP Variable so please also let me know if you find the solution

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条回答 默认 最新

  • douye2020 2015-03-10 11:28
    关注

    try this edit... I have integrated ajax with your code

    <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>
    

    create a new file ajax.php

    and put this code there...

    <?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)){
    
            .
            .
            .
            }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试