Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Random item using jQuery
    text
    copied!<p>Just starting learning about ajax requests using jQuery. I've tried looking at other posts on this but not sure how to implement it. Here's the code I have. Right now it's just getting the first 3 items. I want it to get 3 random items from the rss feed it's pulling. Here's what I have: </p> <pre><code>jQuery(document).ready(function($) { $.ajax({ url: "http://thrive.local/wp-content/themes/thriveafrica/fetcher.php", type: "GET", success: function(d) { $('item', d).slice(0, 3).each(function() { var $item = $(this); var title = $item.find('title').text(); var link = $item.find('link').text(); var description = $item.find('description').text(); var image = $(description).find('img').attr('src'); var price = $(description).find('span.SalePrice').text(); if (price == '') {price = 'Visit Store for Price'}; var html = '&lt;li&gt;&lt;a href="'+link+'" target="_blank"&gt;'; html += '&lt;div class="image"&gt;&lt;img src="'+image+'"&gt;&lt;/div&gt;'; html += '&lt;div class="info"&gt;&lt;strong&gt;'+title+'&lt;/strong&gt;&lt;br/&gt;'+price+'&lt;/div&gt;'; html += '&lt;/a&gt;&lt;/li&gt;'; // Example Output // &lt;li&gt; // &lt;div class="image"&gt;&lt;img src="http://www.thriveafricastore.com/product_images/s/041/coffee__59525_thumb.jpg"&gt;&lt;/div&gt; // &lt;div class="info"&gt;&lt;strong&gt;Thrive Africa Blend (1lb)&lt;/strong&gt;&lt;br&gt;See Price&lt;/div&gt; // &lt;/li&gt; $('div#store ul').append($(html)); }); //End Each } //End Success }); // End Ajax Request }); </code></pre> <p>What are my options?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload