doudou201701 2013-02-01 11:30
浏览 30

如何通过FancyBox传递JavaScript变量?

I'm attempting to pass JavaScript variables via FancyBox, so that I can access them in the window that appears. So far, I have the following code:

<script type="text/javascript">
    var s;
    var e;
    var fancyboxdata = new Array();
    $(function(){
        $('#post_code').blur(function(){
            s = $('#post_code').val();
        });
    });
    function map_routes(e){
        if ((s.length !== 0) && (e.length !== 0)) {
            document.getElementById('map_routes_button').style.visibility="visible";
            fancyboxdata[s] = s;
            fancyboxdata[e] = e;
        } else {
            document.getElementById('map_routes_button').style.visibility="hidden";
        }
    }
</script>
...
<script type="text/javascript">
    $(document).ready(function() {
        $("a.iframe_maps").fancybox({
            ajax: {
                type: "POST",
                data: fancyboxdata
            },
            'hideOnContentClick': true,
            'height': 600,
            'padding': 0,
            'width': 700, 
            'type': 'iframe'
        });
    });
</script>

At this stage, I know the fancyboxdata array contains data, but I'm unsure about the Ajax parameter in the FancyBox function, which is supposed to pass the array variable.

In the window that appears, I have:

<?php

print_r($_POST);

echo $_POST['s'];

?>
<script>
    (function() {
        alert(fancyboxdata[s]);
    })();
</script>

And nothing appears, other than empty arrays and errors in the debugger.

Any ideas?

  • 写回答

2条回答 默认 最新

  • douhuang2218 2013-02-01 11:37
    关注

    Could you not just listen for the submit of the form and an AJAX call separately as in this question (uses jQuery)?

    Can't get form data to post via AJAX using Fancybox

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号