麻烦将php变量传递给模态窗口 [英] trouble passing php variable to modal window

查看:65
本文介绍了麻烦将php变量传递给模态窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将文件modal_window.php加载到当前页面的模式窗口中.

Hi I'm using the following code to load the file modal_window.php into a modal window on the current page.

<style>
        * {
            margin:0; 
            padding:0;
        }

        #overlay {
            position:fixed; 
            top:0;
            left:0;
            width:100%;
            height:100%;
            background:#000;
            opacity:0.5;
            filter:alpha(opacity=50);
        }

        #modal {
            position:absolute;
            background:url(tint20.png) 0 0 repeat;
            background:rgba(0,0,0,0.2);
            border-radius:14px;
            padding:8px;


        }

        #content {
            border-radius:8px;
            background:#fff;
                            padding:20px;

        }

        #close {
            position:absolute;
            background:url(close.png) 0 0 no-repeat;
            width:24px;
            height:27px;
            display:block;
            text-indent:-9999px;
            top:-7px;
            right:-7px;
        }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">  
            </script>
    <script>



        var modal = (function(){
            var 
            method = {},
            $overlay,
            $modal,
            $content,
            $close;

            // Center the modal in the viewport
            method.center = function () {
                var top, left;

                top = Math.max($(window).height() - $modal.outerHeight(), 0) 
                                     / 2;
                left = Math.max($(window).width() - $modal.outerWidth(), 0) 
                                   / 2;

                $modal.css({
                    top:top + $(window).scrollTop(), 
                    left:left + $(window).scrollLeft()
                });
            };

            // Open the modal
            method.open = function (settings) {
                $content.append(settings.content);

                $modal.css({
                    width: settings.width || 'auto', 
                    height: settings.height || 'auto'
                })

                method.center();

                $(window).bind('resize.modal', method.center);

                $modal.show();
                $overlay.show();
            };

            // Close the modal
            method.close = function () {
                $modal.hide();
                $overlay.hide();
                $content.empty();
                $(window).unbind('resize.modal');
            };

            // Generate the HTML and add it to the document
            $overlay = $('<div id="overlay"></div>');
            $modal = $('<div id="modal"></div>');
            $content = $('<div id="content"></div>');
            $close = $('<a id="close" href="#">close</a>');

            $modal.hide();
            $overlay.hide();
            $modal.append($content, $close);

            $(document).ready(function(){

                $('body').append($overlay, 
                            $modal);                        
            });

            $close.click(function(e){
                e.preventDefault();
                method.close();
            });

            return method;
        }());

        // Wait until the DOM has loaded before querying the document
        $(document).ready(function(){

                        varid = '<?php if(isset($_GET['id'])); ?>';


            $('a#testmodal').click(function(e){
                $.get('modal_window.php?id=varid', function(data){
                                      modal.open({content: data});});
                e.preventDefault();
            });





        });



    </script>
</head>
<body>


<a id="testmodal" href="modal.php?id=1">Test</a>

在这样做的同时,我尝试使用以下命令将变量$ id传递给modal_window.php:

While doing so I'm attempting to pass the variable $id to modal_window.php using :

varid = '<?php if(isset($_GET['id'])); ?>';

然后

$('a#testmodal').click(function(e){
                $.get('modal_window.php?id=varid', function(data){
                                      modal.open({content: data});});
                e.preventDefault();
            });

不是将$ id的实际值(在本例中为1)传递给modal_window.php,而是传递给Java脚本变量(变量)的名称.因此,"varid"就是modal_window.php显示的内容.有人看到我在犯错误吗?谢谢!

Instead of the actual value of $id (1 in this case) getting passed to modal_window.php what is getting passed is the name of the java script variable (varid). So "varid" is what is being displayed by modal_window.php. Does anyone see the mistake I'm making? Thanks!

推荐答案

在您的get调用中,您拥有的ID等于文字变量.相反,也许

In your get call you have id equal to the literal varid. Instead maybe

   $.get('modal_window.php?id=' + varid, function(data){
                                  modal.open({content: data});});
            e.preventDefault();
        });

这篇关于麻烦将php变量传递给模态窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆