Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your question is somewhat unclear.</p> <p>I assume that you want to send multiple requests to Yelp and have them processed by different callback functions.</p> <p>You can do that by making a <code>buildCallback</code> method that takes information about the request to generate a callback for and returns a function.</p> <p>You can then use an invocation of that function as the <code>callback</code> parameter, like this: <code>callback=buildCallback('something')</code> It will return a script that looks like this:</p> <pre><code>buildCallback('something')({"message: ... }) </code></pre> <p>This code calls the <code>buildCallback</code> method, then calls the function that the <code>buildCallback</code> method returns.</p> <p>For example:<br> (Assuming that each hotel has a <code>&lt;div class="HotelReviews" id="giveThisToYelp"&gt;</code>)</p> <pre><code>function buildCallback(hotelName) { return function(data) { $.each(data.businesses, function(i,business){ // extra loop $.each(business.reviews, function(i,review){ var content = '&lt;p&gt;Review - ' + review.text_excerpt + ' &lt;a href="http://www.yelp.co.uk/biz/hilton-birmingham-metropole-hotel-solihull"&gt;Read more...&lt;/a&gt;&lt;/p&gt;'; content += 'Rating - &lt;img src="' + business.rating_img_url + '" /&gt;'; content += '&lt;p&gt;Date Added - ' + review.date + '&lt;/p&gt;'; $(content).appendTo('#' + hotelName); }); }); }; } $(function() { $('.HotelReviews').each(function() { $.getScript("http://api.yelp.com/business_review_search?"+ "term=" + this.id + "&amp;location=B26%203QJ"+ "&amp;ywsid=[...]"+ "&amp;callback=buildCallback(" + this.id + ")" ); }); }); </code></pre>
 

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