Solr and JSONP

Need to send an Ajax request to a Solr server that’s on a different domain? You will, of course, need to use JSONP instead of an ordinary JSON request, due to JavaScript’s cross-domain security restrictions. To get a properly padded response from Solr, add the json.wrf parameter to your query string, giving it the name of your callback function. In jQuery:

jQuery.ajax({
  url: mySolrUrl,
  data: myQueryParameters,
  success: mySuccessCallback,
  dataType: 'jsonp',
  jsonp: 'json.wrf'
});

Of course, for this to work the Solr server you’re accessing needs to be publicly accessible, which probably isn’t ideal for security.

jQuery and Ajax in WordPress Plugins – Public Pages

My previous post teaches you how to use jQuery and Ajax for the administration pages in your WordPress plugins. To use them in your user-facing pages requires a few changes.

We’ll use here a simlarly contrived example. Let’s say you use <!--more--> in your longer posts so they don’t fill up too much of your page. Normally, clicking the “Read more…” (or whatever text you use) link takes the user to a separate page with the complete post. In our example, rather than sending the reader to a new page, we’ll make an Ajax request to get the rest of the post and insert it directly into the current page. Continue reading “jQuery and Ajax in WordPress Plugins – Public Pages”

jQuery and Ajax in WordPress Plugins – Administration Pages

This is a quick overview of how to use jQuery and its Ajax functions in WordPress. To get the point across, I’ll use a simple and contrived example. We’ll have an admin screen with a list of categories. Clicking on the name of one of the categories will fetch a list of titles of posts in that category and display them as a sub-list of that category. Continue reading “jQuery and Ajax in WordPress Plugins – Administration Pages”