Errors Related to the Use of CFAJAX Tags in ColdFusion

Adobe ColdFusion logo

This is a quick change that is easily missed when adding AJAX functionality to an old ColdFusion site with CFAJAX tags. In my case, I was adding this functionality to a site that had originally been developed about ten years ago. This site runs on a Windows server with IIS.

After getting the site upgraded and working properly in the dev and test environments, I discovered that several errors were happening in prod that never happened in test or dev. The most common of these errors was “ColdFusion is undefined”.

Of all things, the Virtual Directory to CFIDE had never been created. As is so common, major problems can be caused by tiny bugs in code, or in this case, in the Web server configuration itself.

Create a Virtual Directory in the root of the website and name it CFIDE. It should, in most cases, point to C:\inetpub\wwwroot\CFIDE. Once this is done, the CFAJAX errors should be no more!

UPDATE via Gavin Pickin (@gpickin):

Making the SyntaxHighlighter Evolved Plugin Work with Infinite Scroll on WordPress.org Sites

WordPress logo

SyntaxHighlighter Evolved is a great plugin to format source code on a WordPress.org blog. Also, WordPress.org blogs can now allow you to use Infinite Scroll, which uses AJAX to load posts as you scroll down the blog.

The problem is that once you begin scrolling past the first block of posts that were initially loaded, the posts loaded using Infinite Scroll no longer highlight the code.

The fix is to call the “SyntaxHighlighter.highlight()” method each time a block of posts are loaded.

I’m sure there are many ways this could be done. The way I chose was to take this block of code from the file “jetpack/modules/infinite-scroll/infinity.php”:

// If primary and fallback rendering methods fail, prevent further IS rendering attempts. Otherwise, wrap the output if requested.
if ( empty( $results['html'] ) ) {
    unset( $results['html'] );
    do_action( 'infinite_scroll_empty' );
    $results['type'] = 'empty';
} elseif ( $this->has_wrapper() ) {
    $wrapper_classes = is_string( self::get_settings()->wrapper ) ? self::get_settings()->wrapper : 'infinite-wrap';
    $wrapper_classes .= ' infinite-view-' . $page;
    $wrapper_classes = trim( $wrapper_classes );

    $results['html'] = '<div class="' . esc_attr( $wrapper_classes ) . '" id="infinite-view-' . $page . '" data-page-num="' . $page . '">' . $results['html'] . '</div>';
}

and add this one line to the block:

$results['html'] .= '<script type="text/javascript">SyntaxHighlighter.highlight();</script>';

resulting in this block:

// If primary and fallback rendering methods fail, prevent further IS rendering attempts. Otherwise, wrap the output if requested.
if ( empty( $results['html'] ) ) {
    unset( $results['html'] );
    do_action( 'infinite_scroll_empty' );
    $results['type'] = 'empty';
} elseif ( $this->has_wrapper() ) {
    $wrapper_classes = is_string( self::get_settings()->wrapper ) ? self::get_settings()->wrapper : 'infinite-wrap';
    $wrapper_classes .= ' infinite-view-' . $page;
    $wrapper_classes = trim( $wrapper_classes );

    $results['html'] = '<div class="' . esc_attr( $wrapper_classes ) . '" id="infinite-view-' . $page . '" data-page-num="' . $page . '">' . $results['html'] . '</div>';
    $results['html'] .= '<script type="text/javascript">SyntaxHighlighter.highlight();</script>';
}

Save the file and reload your blog. All code blocks should now be highlighted as you scroll!