Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使每个项目/物品的愿望清单动态化_Javascript_Php_Jquery_Ajax_Arraylist - Fatal编程技术网

Javascript 使每个项目/物品的愿望清单动态化

Javascript 使每个项目/物品的愿望清单动态化,javascript,php,jquery,ajax,arraylist,Javascript,Php,Jquery,Ajax,Arraylist,嗨,我有一个小问题,我有一个whish列表脚本,它将商店中的艺术品添加到一个会话中并保存它们,但当我单击哪个列表时,他只添加第一个项目如何动态显示,每次单击愿望列表都是针对商店中的单个项目 我的文章结构,单击wlbutton1或wlbutton2后,他应该将id1或ID2的文章添加到愿望列表中: echo '<div class="span3 filter--'.$obj->product_prop1.'" data-price="'.substr($obj->pric

嗨,我有一个小问题,我有一个whish列表脚本,它将商店中的艺术品添加到一个会话中并保存它们,但当我单击哪个列表时,他只添加第一个项目如何动态显示,每次单击愿望列表都是针对商店中的单个项目

我的文章结构,单击wlbutton1或wlbutton2后,他应该将id1或ID2的文章添加到愿望列表中:

    echo '<div class="span3 filter--'.$obj->product_prop1.'" data-price="'.substr($obj->price, 0, -3) . '" data-popularity="3" data-size="s|m|xl" data-color="pink|orange" data-brand="'.$obj->product_brand.'">'; 
        echo '<div class="product">'; 
        echo '<div class="product-img featured">'; 
        echo '<form method="post" action="../cart_update.php">';
        echo '<div class="picture"><img src="images/'.$obj->product_img_name.'">';
        echo '<div class="img-overlay"><button class="add_to_cart btn more btn-primary">Kaufen</button><a href="#" class="btn buy btn-danger" id="producturl'.$obj->id.'">...mehr</a></div>';
        echo '</div>';
        echo '</div>';
        echo '<div id="result"></div>';
        echo '<div class="main-titles"><h4 class="title">'.$currency.$obj->price.'</h4>';
        echo '<h5 class="no-margin isotope--title" id="product'.$obj->id.'">'.$obj->product_name.'</h5>';
        echo '<p class="no-margin pacifico" style="position: absolute;right: 10px;top: 5px; text-transform: capitalize;">'.$obj->product_brand.'</p>';
        echo '<p class="no-margin" style="position: absolute;right: 10px;top: 25px;"><a class="wl-button'.$obj->id.'"><i class="icon-gift"></i></a></p>';
        echo '</div>';
        echo '<p class="desc">'.substr($obj->product_desc, 0, 160) . '...</p>';
        echo '<input type="hidden" name="product_qty" value="1" />';
        echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
        echo '<input type="hidden" name="type" value="add" />';
        echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
        echo '</form>';
        echo '</div>';
        echo '</div>';

下面是一个示例,说明如何查找添加文章所需的数据。 首先是HTML示例:

<div class="products">
    <form>
        <p>
            <!-- Fist article -->
            <span>Article 1</span>
            <!-- A name construct so that I can easilly find in which iteration of the loop I am -->
            <input type="hidden" name="article[0].id" value="1" />
            <input type="hidden" name="article[0].name" value="article1" />
            <button class="addButton">Add article</button>
        </p>
        <p>
            <!-- Second article -->
            <span>Article 2</span>
            <input type="hidden" name="article[1].id" value="2" />
            <input type="hidden" name="article[1].name" value="article2" />
            <button class="addButton">Add article</button>
        </p>
        <!-- … others articles -->
    </form>
</div>
通过这样工作,您可以向服务器发送将文章添加到愿望列表所需的数据

这里是链接到

在本例中,您可以通过按钮了解如何处理HTML内容以查找输入


您可以通过找到有关“树遍历”的更多信息。

我看不到任何ID为“product”或“producturl”的元素。同样,我没有找到任何CSS类为“wl button”的元素。也许你应该写一些东西,比如:
$('h5[id^='product']).text()以便它在所有ID以“产品”开头的H5上工作。你能在没有PHP代码的情况下重写你的HTML代码吗?(通过一个具体的例子)它应该像i wnt一样动态生成wl-button1、wl-button2等。在jquery中使用$this动态地在id后面添加一个数字??CSS类不需要像id那样唯一。id也不是必须的。你可以为你的脚本解决这个问题:你可以搜索你的动作按钮来找到你需要的所有数据。我将尝试向您展示一个示例代码。伟人我知道找到元素并可以将它们发送到我的php文件中,该文件用于会话,但现在我遇到了另一个问题,每次他添加一篇文章时,他都会删除我的会话和文章,然后我才能解决此问题。这里是我的wlscript.php
抱歉:我只知道php的基本知识。在那件事上我帮不了你。
<div class="products">
    <form>
        <p>
            <!-- Fist article -->
            <span>Article 1</span>
            <!-- A name construct so that I can easilly find in which iteration of the loop I am -->
            <input type="hidden" name="article[0].id" value="1" />
            <input type="hidden" name="article[0].name" value="article1" />
            <button class="addButton">Add article</button>
        </p>
        <p>
            <!-- Second article -->
            <span>Article 2</span>
            <input type="hidden" name="article[1].id" value="2" />
            <input type="hidden" name="article[1].name" value="article2" />
            <button class="addButton">Add article</button>
        </p>
        <!-- … others articles -->
    </form>
</div>
$(document).ready(function(){
    $(".addButton").on("click", function(event){
        event.preventDefault();
        var button = $(this);
        var parent = button.parent(); // We need to find the container in which to seach our fields.
        var idArticle = parent.find("input[name$='.id']").val(); // Find the ID
        var nameArticle = parent.find("input[name$='.name']").val(); // Find ather data
        alert("Add article with id = " + idArticle + " and name = " + nameArticle);
        // Next step is the ajax method to call the server with the correct data. 
    });
});