1
什麼即時試圖做的:只從一個產品獲得JSON數據shopify
當我點擊收藏頁面網格產品,我試圖讓產品的稱號等用ajax。
繼承人我的代碼:
{% for product in collection.products %}
<div class="product">
{% capture producturl %}{{ product.url }}{% endcapture %}
<a class="ajax ajax{% increment ajaxno %}">
PRODUCT IMAGE
</a>
</div>
<script>
jQuery(function ($) {
$("a.ajax0").click(function(){
jQuery.getJSON('{{ producturl }}.js', function(product) {
console.log('The title of this product is ' + product.title);
});
});
});
</script>
{% endfor%}
但是當我點擊任何產品,即時得到警報所有當前頁面上的產品。 我該如何調整我的代碼才能得到我點擊的產品的標題?
感謝。兩者都適合我 – wsgg