{"id":20791,"date":"2013-03-26T09:30:51","date_gmt":"2013-03-26T16:30:51","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=20791"},"modified":"2015-10-22T11:25:37","modified_gmt":"2015-10-22T18:25:37","slug":"034-ajaxing-in-a-blog-post","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/lodge\/artists-website\/034-ajaxing-in-a-blog-post\/","title":{"rendered":"#034 – Ajaxing in a Blog Post"},"content":{"rendered":"

We end up with a really simple test which loads in an article from the blog to display if there is room:<\/p>\n

\/\/ Load additional content if enough room\r\nenquire\r\n  .register(\"(min-width: 700px)\", {\r\n    match: function() {\r\n      $(\"#home-article\").load(\"\/blog\/ #main-article\");\r\n    }\r\n  })\r\n  .listen();<\/code><\/pre>\n

jQuery makes Ajax super easy, and even easier with the .load()<\/a> 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.<\/p>\n

Sorry about the not-great sound on this one =(<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":19998,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"lodge-video.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":5968,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/fixing-load-in-ie-for-cached-images\/","url_meta":{"origin":20791,"position":0},"title":"Fixing .load() in IE for cached images","date":"March 19, 2010","format":false,"excerpt":"The .load() function fires when the element it's called upon is fully loaded. It is commonly used on images, which may not be fully loaded when the JavaScript originally runs, and thus would return incorrect information about themselves (e.g. height\/width). Most browsers deal with this fine. IE can cause problems,\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":148806,"url":"https:\/\/css-tricks.com\/lodge\/learn-jquery\/05-dom-ready\/","url_meta":{"origin":20791,"position":1},"title":"#05: All About DOM Ready","date":"September 2, 2013","format":false,"excerpt":"We've talked a good bit about selectors. A jQuery selector like $(\"h1\") will select all elements on the page. But what about... when it doesn't? Here's an example of when that selector would fail: Learning jQuery Hello, World! Will that element be red? Nope. WTF right? The reason it doesn't\u2026","rel":"","context":"With 6 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8893,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/window-load-event-with-minimum-delay\/","url_meta":{"origin":20791,"position":2},"title":"Window load event with minimum delay","date":"April 1, 2011","format":false,"excerpt":"window.load can fire super duper fast if the page is cached. If you want to use that event but make sure a minimum amount of time has passed until it does... (function fn() { fn.now = +new Date; $(window).load(function() { if (+new Date - fn.now < 500) setTimeout(fn, 500); \/\/\u2026","rel":"","context":"With 1 comment","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7720,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/load-jquery-only-if-not-present\/","url_meta":{"origin":20791,"position":3},"title":"Load jQuery Only If Not Present","date":"October 19, 2010","format":false,"excerpt":"Say you were going to do an include on a whole bunch of pages, and inside of that include you wanted to do some jQuery specific stuff. That page may or may not already have jQuery loaded. If it already does, you don't want to load it again, but if\u2026","rel":"","context":"With 21 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3780,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/loading-jquery\/","url_meta":{"origin":20791,"position":4},"title":"Loading jQuery","date":"September 4, 2009","format":false,"excerpt":"Load with Google API Direct Link to Google Check if loaded, only load if unloaded var jQueryScriptOutputted = false; function initJQuery() { \/\/if the jQuery object isn't available if (typeof(jQuery) == 'undefined') { if (! jQueryScriptOutputted) { \/\/only output the script once.. jQueryScriptOutputted = true; \/\/output the script (load it\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4142,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/load-only-a-section-of-a-page\/","url_meta":{"origin":20791,"position":5},"title":"Load Only a Section of a Page","date":"September 18, 2009","format":false,"excerpt":"Use Case You want to AJAX load a section of another page on your site onto the current page. Say your eCommerce CMS system creates a dynamic menu of products, but that exists as a subdirectory of your site and you want to use that on the homepage. jQuery $(\"#mainNav\").load(\"\/store\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/20791"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=20791"}],"version-history":[{"count":4,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/20791\/revisions"}],"predecessor-version":[{"id":210063,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/20791\/revisions\/210063"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/19998"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=20791"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=20791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}