#034 – Ajaxing in a Blog Post

(Updated on )

We end up with a really simple test which loads in an article from the blog to display if there is room:

// Load additional content if enough room
enquire
  .register("(min-width: 700px)", {
    match: function() {
      $("#home-article").load("/blog/ #main-article");
    }
  })
  .listen();

jQuery makes Ajax super easy, and even easier with the .load() function. The only little trick here is where we’ve added #main-article to the end up the URL which limits what it injects onto the page to that CSS selector. It would be more perfect if we engineered some solution to only return the content we need to add, but this is a such a quick and easy solution it’s kind of beautiful.

Sorry about the not-great sound on this one =(.