Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery load local iframe url with escaped characters for disqus commenting
    primarykey
    data
    text
    <p>I'm loading a custom page type that is just comments for a post. This is so I can use Disqus threads for easier usability when multiple loop posts are on a single page.</p> <p>When loading an <code>iFrame</code> with the following structure I keep getting this syntax error. Are my escape characters wrong?</p> <pre><code>$(".boxyComments a").click(function (event) { event.preventDefault(); var post_id = $(this).attr("rel"); $(".commentsIframeBig") .get(0).contentWindow.location.href = $("&lt;?php echo get_site_url(); ?&gt;","\/ajax-post-fold\/",post_id); </code></pre> <p>What's happening is the <code>get</code> retrieves the Wordpress hook to print the site url (in this case it prints <code>http://whateverdomainex.com</code> for the 1st call, 2nd should print <code>/ajax-post-fold/</code> and the last call should print the post ID so the entire url ends up printing as <code>http://whateverdomanex.com/ajax-post-fold/2825</code>.</p> <p>Instead my Chrome console gives me the following message:</p> <p><code>Uncaught Error: Syntax error, unrecognized expression: /ajax-post-fold/</code></p> <p><strong>Update</strong></p> <p>I've put this variable into place and called it rather than the <code>$("&lt;?php echo get_site_url(); ?&gt;","\/ajax-post-fold\/",post_id);</code> as the <code>get</code> reference:</p> <pre><code>var postLink = $("&lt;?php echo get_site_url(); ?&gt;"+"\/ajax-post-fold\/"+post_id); </code></pre> <p>Implemented as such:</p> <pre><code>$(".boxyComments a").click(function (event) { event.preventDefault(); var postLink = $("&lt;?php echo get_site_url(); ?&gt;"+"\/ajax-post-fold\/"+post_id); var post_id = $(this).attr("rel"); $(".commentsIframeBig") .get(0).contentWindow.location.href = postLink; </code></pre> <p>Which gives me the following Chrome message:</p> <pre><code>Uncaught Error: Syntax error, unrecognized expression: http://www.theciv.com/ajax-post-fold/28448 </code></pre> <p>The URL that should be in the <code>src</code> attribute for the <code>iFrame</code> looks like it should be fine and good to go, so why is this syntax error still being output?</p> <p><strong>UPDATE</strong></p> <pre><code>var postLink = "&lt;?= site_url('\/ajax-post\/'); ?&gt;"+post_id; $(this).closest(".boxy").find(".commentsIframeBig") .css("display","block") .animate({height: "100%"}, 500) .get(0).contentWindow.location.href = postLink; </code></pre> <p>With the proper structure above, the custom page is now loading in the iFrame. However the additional construct of <code>+page_id</code> which includes the <code>rel</code> attribute containing the post's id isn't loading properly.</p> <p>Moreover when calling the new url as it's original custom page template, then adding the post's id does not load the correct page with post id. Confused yet? Read it again. Took me awhile to write that sentence.</p> <p>In any case, now my mission to have the post id load when adding the custom page and the <code>post_id</code> as an added string for the iFrame's url to load properly.</p> <p><strong>update</strong></p> <p>Here is final working code to load Disqus comments into same page, pseudo multiple times.</p> <p>Basically this is pushing a <code>post id</code> to the end of a custom page type, resulting in the post's content and attributable elements being loaded into the custom page template.</p> <p>When stripping that custom page template down to just show the comments for the page, you can create a load/unload reaction whereby you are only calling Disqus once, removing that instance and then loading it again when another <code>Load Comments</code> button is clicked within a subsequently loaded post on the same page. Yay. Multiple Disqus commenting on one page with minimal Ajax loading.</p> <p>Here is the structure et al that is almost working for me. Only 2 bugs left. First is the secondary load when emptying, then reloading the new Disqus page into the Ajax element using the <code>.ajaxComplete()</code> callback function.</p> <p>What's happening now is the callback is basically not being fired at all. As far as I can tell. Clicking on it a second time however, does make the call. But this is due to the class parameters being met for the <code>else</code> statement.</p> <p>Second bug left is I'm having a hard time figuring out how to get the appropriate elements to enlarge, while leaving the others the same size.</p> <pre><code>// Load comments and/or custom post content $(".boxyComments a").click(function (event) { event.preventDefault(); $.ajaxSetup({cache:false}); var post_id = $(this).attr("rel"); var excHeight = $(this).closest('.boxy').find('.initialPostLoad').height(); var postHeight = $(this).closest('.boxy').find('.articleImageThumb').height(); var postWidth = $(this).closest('.boxy').find('.articleImageThumb').width(); // close other comments boxes that may already be open if($('.commentsOpen').length ) { console.log('comments are open'); $('.bigBoxy').closest('.boxy') .animate({height:(postHeight + excHeight)}, 500); $('.showComments') .removeClass('bigBoxy') .removeClass('commentsOpen'); $('.commentsAjax') .empty(function(){ $(this).closest(".boxy").find(".showComments") .addClass("commentsOpen") .addClass("bigBoxy"); $(".bigBoxy").find(".commentsAjax ") .css("display","block") .animate({height: "500px"}, 500) .load("http://&lt;?php echo $_SERVER[HTTP_HOST]; ?&gt;/ajax-post/",{id:post_id}); $(this).closest(".boxy") .ajaxComplete(function() { var excHeight = $(this).closest('.boxy').find('.initialPostLoad') .height(); var postHeight = $(this).closest('.boxy').find('.articleImageThumb') .height(); $(this).closest(".boxy").animate({height: (postHeight + excHeight)}, 500) }); }); } else { $(this).closest(".boxyComments").find(".showComments") .addClass("commentsOpen") .addClass("bigBoxy"); $(this).closest(".boxy").find(".commentsAjax") .css("display","block") .animate({height: "500px"}, 500) .load("http://&lt;?php echo $_SERVER[HTTP_HOST]; ?&gt;/ajax-post/",{id:post_id}); $(this).closest(".boxy") .ajaxComplete(function() { var excHeight = $(this).closest('.boxy').find('.initialPostLoad') .height(); var postHeight = $(this).closest('.boxy').find('.articleImageThumb') .height(); $(this).closest(".boxy").animate({height: (postHeight + excHeight)}, 500) }); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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