【发布时间】:2016-08-05 09:27:18
【问题描述】:
我想做什么:
当我在集合页面网格中单击产品时,我正在尝试使用 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%}
但是当我点击任何产品时,我会收到当前页面上所有产品的警报。 如何调整我的代码以仅获取我正在单击的产品的标题?
【问题讨论】: