grab or load text on demand

You should really take a look at the AJAX in Plugins article. It gives examples of how to setup AJAX the proper way in WordPress.

Here’s the basic workflow of using AJAX in WordPress:

  1. Create an enqueue your custom JavaScript file that uses jQuery.post or jQuery.get or jQuery.ajax
  2. Create a callback for the wp_ajax action hook (learn the difference between normal and nopriv hooks)
  3. Within your callback function, you would create some logic that would echo whatever type of content you choose (make sure to exit or die() at the end of the callback)

It’s best if you learn to fish on this one rather than someone doing the fishing for you. 🙂