如何使用ajax和javascript构建图像组合

如何使用ajax和javascript构建图像组合,javascript,php,ajax,colorbox,Javascript,Php,Ajax,Colorbox,我正试图通过按缩略图来启动图像组合。在用户按下缩略图之前,构建公文包的代码不会运行。这是我的 我实际上是在尝试在我的网站上实现这些功能。 工作流程是: 1.将显示带有缩略图的投资组合列表 2.选择缩略图后,将生成并显示公文包 下面的代码正常工作。选择缩略图后,将启动公文包,一切正常。这是用循环测试的,每次加载页面时都会执行 <a class="group2" href="'.$cacheDataPath . $thumbnail.'"> <img style="display

我正试图通过按缩略图来启动图像组合。在用户按下缩略图之前,构建公文包的代码不会运行。这是我的

我实际上是在尝试在我的网站上实现这些功能。

工作流程是: 1.将显示带有缩略图的投资组合列表 2.选择缩略图后,将生成并显示公文包

下面的代码正常工作。选择缩略图后,将启动公文包,一切正常。这是用循环测试的,每次加载页面时都会执行

<a class="group2" href="'.$cacheDataPath . $thumbnail.'">
<img style="display: inline-block" src="'.$cacheDataPath . $thumbnail.'" width="100" height="100"></a>

为了在选择时(而不是每次加载页面时)构建公文包,我正在使用这个功能

<a href="javascript:void(0)" onclick="buildColorboxPortfolio()">

function buildColorboxPortfolio() {
      $.ajax({
       type: "POST",
       url: 'http://ec2-xx-xx-xx-xx.compute-1.amazonaws.com/build_portfolio.php',
       data:{action:'test'},
       async:false,
       complete: function (response) {
       jQuery('#output').html(response.responseText);
      }
    //      alert(html);
  });

试验

'; echo$html;
有人能告诉我怎么让它工作吗?html被正确返回,我可以按下测试url以正确启动公文包…但是我需要它在原始onclick上自动运行


非常感谢您的帮助。

我建议您首先停止将所有HTML包装在PHP字符串中。没必要


要解决此问题,请不要
返回false#click()
方法中的code>。

感谢您的回复。我试图消除返回错误;但一切都没有改变。关于html,谢谢你的建议。一旦我把它放进公文包中,它就会被清理干净。从onclick中删除“()”,使它看起来像
onclick=“buildColorboxPortfolio”
没有乐趣。如果没有这些,它根本不会调用函数。那潜水舱呢?现在按缩略图返回测试。因此,$html.='然后测试url将正确启动公文包。我需要在我的主脚本中使用div吗?不确定这是否可能…但这需要在推缩略图时加载。现在它在按下测试时加载。将
href=“javascript:void(0)”替换为
href=“#”
<a class="group2" href="'.$cacheDataPath . $thumbnail.'">
<?php
$html = '<html>
    <head>
            <meta charset=\'utf-8\'/>
            <title>Colorbox Examples</title>
            <style>
            </style>
            <link rel="stylesheet" href="/colorbox-master/example1/colorbox.css" />
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
            <script src="/colorbox-master/jquery.colorbox.js"></script>
            <script>
                    $(document).ready(function(){
                            //Examples of how to assign the Colorbox event to elements
                            $(".group3").colorbox({rel:\'group3\', transition:"none", width:"75%", height:"75%"});
                            $(".group2").colorbox({rel:\'group2\', transition:"none", width:"75%", height:"75%"});
                            //Example of preserving a JavaScript event for inline calls.
                            $("#click").click(function(){
                                    $(\'#click\').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
                                    return false;
                            });
                    });
            </script>
    </head>

    <body>

            <a class="group3" href="/colorbox-master/content/ohoopee1.jpg" title="Me and my grandfather on the Ohoopee.">TEST</a>
            <p><a class="group3" href="/colorbox-master/content/ohoopee2.jpg" title="On the Ohoopee as a child"></a>TEST</p>
            <p><a class="group3" href="/colorbox-master/content/ohoopee3.jpg" title="On the Ohoopee as an adult"></a></p>
    </body>
</html>';
echo $html;