javascript - 站点使用 jquery 和 wp_enqueue_script 显示空白屏幕

标签 javascript php jquery

<分区>

没有显示错误信息。只是空白的白色屏幕。

Firefox 的控制台显示:未声明 HTML 文档的字符编码。如果文档包含 US-ASCII 范围之外的字符,则在某些浏览器配置中,文档将呈现为乱码文本。页面的字符编码必须在文档或传输协议(protocol)中声明。

在我的 functions.php 文件中,我添加了这段代码:

    function comparison_js() {
    wp_register_script( 'custom-script', get_template_directory_uri() . '/js/comparison-js.js', array( 'jquery' ),'1.0.0',true  );
    wp_enqueue_script( 'custom-script' );
     );
    }
    add_action( 'wp_enqueue_scripts', 'comparison-js' );

我实际的 javascript 文件:

    jQuery(document).ready(function($) {
        jQuery('a').on('click', function(e){    
    //Prevent the link from working as an anchor tag
    e.preventDefault();

    //Declare 'this' outside of AJAX because of asynchronous nature of call
    that = jQuery(this);

    //Make AJAX call to the PHP file/database query
    jQuery.ajax({
        url:'http://dirtypoliticsph.com/wp-content/themes/twentythirteen/templatecode.php',
        type:'POST',
        data:{id:jQuery(this).data('id')},
        success:function(data){
            that.append(data);
        }
            });
        });
    });

在我将新的 wp_enqueue_script 函数添加到我的 functions.php 文件后出现空白屏幕。如果我删除代码,网站就会正常运行。

最佳答案

您有语法错误 - 额外的 );。请将其删除,以便您的功能变为:

function comparison_js() {
    wp_register_script( 'custom-script', get_template_directory_uri() . '/js/comparison-js.js', array( 'jquery' ),'1.0.0',true  );
    wp_enqueue_script( 'custom-script' );
}

请考虑使用带有语法错误突出显示的 IDE,这样可以避免此类偶然错误

关于javascript - 站点使用 jquery 和 wp_enqueue_script 显示空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315659/

相关文章:

javascript - 使用jquery获取span的高度

php - Zend DB 获取不同计数

jquery - 如何检查href是否包含变量

javascript - 自动刷新包含 Twitter 帖子的 div

php - 在 PHP 或 JavaScript 中查询大型 XML 文件(600mb+)?

javascript - 外部调用 jQuery 扩展函数

javascript - 如何在 svelte 文件中使用 electron 方法 - Svelte 3 - 或者还有其他方法吗?

php - concat 函数修剪我的变量

php - 如何在ajax链接函数中传递js变量

javascript - 如何使用 AngularJS 制作基于单选按钮值的下拉列表?