我正在使用一个购物脚本,当您点击屏幕底部时,可以在同一页面上加载新产品,例如 Facebook 等。当您调用 page1 之类的页面时,可以为每个页面获取一个 AJAX 字符串.ajax 或 page2.ajax。我已经阅读了许多文章和教程,但我无法弄清楚这一点。
到目前为止,我所拥有的是:
HTML
<div id="collection-ajax">
<div class="productsGrid">
// products on page 1 //
</div>
// WHEN CATEGORIE HAS MORE PAGES THIS HAVE TO BE SHOWN AFTER THE PRODUCTS ABOVE
<div id="loadmoreajaxloader" style="display:none;"><img src="ajax-loader.gif" /></div>
AJAX 字符串(看起来像 json)是我放弃的其余产品之一:
{"page":1,"pages":2,"count":42,"url":"http:\/\/meules1.webshopapp.com\/woonkamer-en-keuken\/","products":[{"id":1750137,"vid":2765003,"image":"http:\/\/cdn.webshopapp.com\/i\/z1faly\/50x50x2\/newc.jpg","image_id":2156769,"brand":false,"code":"40-95407","ean":"40-95407","sku":"","score":false,"price":{"price":65,"price_money":"\u20ac65,00","price_money_with_currency":"\u20ac65,00 EUR","price_money_without_currency":"65,00","price_excl":54.6218,"price_excl_money":"\u20ac54,62","price_excl_money_with_currency":"\u20ac54,62 EUR","price_excl_money_without_currency":"54,62","price_incl":65,"price_incl_money":"\u20ac65,00","price_incl_money_with_currency":"\u20ac65,00 EUR","price_incl_money_without_currency":"65,00","price_old":109,"price_old_money":"\u20ac109,00","price_old_money_with_currency":"\u20ac109,00 EUR","price_old_money_without_currency":"109,00","price_old_excl":91.5966,"price_old_excl_money":"\u20ac91,60","price_old_excl_money_with_currency":"\u20ac91,60
Jquery 是我面临的问题。我个人认为是这样的:
<script type="text/javascript">
var collectionPage = {{ collection.page }};
var collectionPages = {{ collection.pages }};
function loadCollectionContent(){
if(collectionPage < collectionPages){
collectionPage++;
var url = 'http://shop.com/page' + collectionPage + '.ajax';
$.getJSON(url, function(data){
var listItems = [];
$.each(data.products, function(index, product){
var itemHtml = ''
// HERE I'M STUCK ON WHAT TO DO NEXT
有人可以指点我一些方向吗?或者帮我写代码?如果您需要更多信息,请告诉我。