如何将附加数据传递到 ajax post jquery ui 可选择网格 ->奇特盒子?

发布于 2024-12-13 13:41:22 字数 1810 浏览 1 评论 0原文

我需要帮助合并两个 jQuery ui 的可选(网格)和花式框(灯箱解决方案)。

现在,精美的框使 ajax 帖子变得非常简单(ahref="link to page")并显示它!问题是 jQuery ui 可选择为我抓取数据并将其附加到页面,但我想使用 ajax 将其发布到 fancybox,以便在我的 php 分析数据后弹出提示。

这是我到目前为止所拥有的

$x = array();
    while($row = mysql_fetch_array($bq)){
        $x[]= "
        <li  class=\"ui-widget-content\"
        data-morph=\"".$row['morph']."\"  
        data-price=\"".$row['price']."\"
        id=\"".$row['id']."\">
        $ ".$row['price'].".00&nbsp;
        ".$row['morph']."&nbsp;
        ".$row['sex']."&nbsp;
        </li>";
    }   


}
<p id="feedback">
<span>You've selected:</span> <span id="select-result">none</span>.
</p>
<ol><? echo "Total Snakes ($ts)"; if($ts != '0'){echo "<button class=\"ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all\">
        <span class=\"ui-button-text\" href=\"?ready\">Buy</span>
    </button>";} ?></ol>
<ol id="selectable">
<?php
shuffle($x);
foreach($x as $z){
    echo $z;    
}
?>
</ol>
<script>    
$(function() {
        $( "#selectable" ).selectable({
            stop: function() {
                var result = $( "#select-result" ).empty();
                $( ".ui-selected").each(function() {
                     var id = $( this ).attr('id'); 
                     var morph = $(this).attr('data-morph');
                     var price = $(this).attr('data-price');

                    result.append( (id)+',' );
/// this gets displayed on the page but i want this data to be passed to fancy box ....
                    });


            }
        });

    });
    $('button span').fancybox({
// maybe somebody would kno how ?
});
</script> 

I need help incorporating the two jQuery ui's selectable (grid) and fancy box (lightbox solution).

Now the fancy box makes a ajax post really simple (ahref="link to page") and displays it! The problem is that the jQuery ui selectable grabs the data for me and appends it to the page but I would like to post it with ajax to the fancybox, to popup a prompt after the data has been analyzed by my php.

Here's what I have so far

$x = array();
    while($row = mysql_fetch_array($bq)){
        $x[]= "
        <li  class=\"ui-widget-content\"
        data-morph=\"".$row['morph']."\"  
        data-price=\"".$row['price']."\"
        id=\"".$row['id']."\">
        $ ".$row['price'].".00 
        ".$row['morph']." 
        ".$row['sex']." 
        </li>";
    }   


}
<p id="feedback">
<span>You've selected:</span> <span id="select-result">none</span>.
</p>
<ol><? echo "Total Snakes ($ts)"; if($ts != '0'){echo "<button class=\"ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all\">
        <span class=\"ui-button-text\" href=\"?ready\">Buy</span>
    </button>";} ?></ol>
<ol id="selectable">
<?php
shuffle($x);
foreach($x as $z){
    echo $z;    
}
?>
</ol>
<script>    
$(function() {
        $( "#selectable" ).selectable({
            stop: function() {
                var result = $( "#select-result" ).empty();
                $( ".ui-selected").each(function() {
                     var id = $( this ).attr('id'); 
                     var morph = $(this).attr('data-morph');
                     var price = $(this).attr('data-price');

                    result.append( (id)+',' );
/// this gets displayed on the page but i want this data to be passed to fancy box ....
                    });


            }
        });

    });
    $('button span').fancybox({
// maybe somebody would kno how ?
});
</script> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城旧梦 2024-12-20 13:41:22

您知道,实际上可以通过在 PHP 中使用单引号来避免放置所有这些斜杠,如下所示:

$x[]= '<li  class="ui-widget-content" data-morph="'.$row['morph'].'" data-price="'.$row['price'].'" id="'.$row['id'].'">' ; // and so on

至于问题,我有同样的任务。我发现这个链接很有帮助:

post array jquery serialize

就个人而言,我刚刚将一个 js 数组传递给我的PHP ajax 脚本:

function saveOrder(){
    var ids = new Array();

    $('#sortable').find('li').each(function(i){ 
        ids.push($(this).attr('id'));
    });

    $.ajax({
        type: "POST",

        url: 'ajax/reorder_panel.php',

        data: {
            order: ids
        },

        success: function(data, textStatus, jqXHR){
            alert(data);
        },

        error: function(jqXHR, textStatus, errorThrown){
            alert("Server connection error...");
        }
    });
}

You know, you can actually avoid putting all those slashes by using single quotation marks in PHP as follows:

$x[]= '<li  class="ui-widget-content" data-morph="'.$row['morph'].'" data-price="'.$row['price'].'" id="'.$row['id'].'">' ; // and so on

As to the question, I have the same task. I found this link helpful:

post array jquery serialize

Personally, I just passed a js array to my PHP ajax script:

function saveOrder(){
    var ids = new Array();

    $('#sortable').find('li').each(function(i){ 
        ids.push($(this).attr('id'));
    });

    $.ajax({
        type: "POST",

        url: 'ajax/reorder_panel.php',

        data: {
            order: ids
        },

        success: function(data, textStatus, jqXHR){
            alert(data);
        },

        error: function(jqXHR, textStatus, errorThrown){
            alert("Server connection error...");
        }
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文