我正在创建一个只使用主页的主题。单击按钮后,该部分的内容将通过AJAX(下面的脚本)加载到主页上的div中。
$.ajaxSetup ({
cache: false
});
var ajax_load = "<center><img src=\'<?php bloginfo("template_url"); ?>/images/loading.gif\' alt=\'Loading...\' /></center>";
var loadUrl = "http://localhost:8888/cnNew/?portfolio=portfolio-test";
$("#ourTeam").click(function(){
$("#main")
.html(ajax_load)
.load(loadUrl + " #content");
});
所有的。正在通过wp\\u enqueue\\u脚本加载js文件:function my_init() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script(\'jquery\');
wp_register_script(\'jquery\', \'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js\', false, \'1.4.3\');
wp_enqueue_script(\'jquery\');
wp_enqueue_script( \'galleria_plugin\', get_bloginfo(\'template_directory\') . \'/js/galleria.js\', array(\'jquery\') );
}
}
add_action(\'init\', \'my_init\');
function my_scripts() {
wp_enqueue_script( \'carousel\', get_bloginfo(\'template_directory\') . \'/js/carousel.js\', array(\'jquery\') );
wp_enqueue_script( \'backstretch\', get_bloginfo(\'template_directory\') . \'/js/jquery.backstretch.min.js\', array(\'jquery\') );
wp_enqueue_script( \'nivo_slider\', get_bloginfo(\'template_directory\') . \'/js/jquery.nivo.slider.pack.js\', array(\'jquery\') );
wp_enqueue_script( \'tabify\', get_bloginfo(\'template_directory\') . \'/js/jquery.tabify-1.4.js\', array(\'jquery\') );
wp_enqueue_script( \'mouse_wheel\', get_bloginfo(\'template_directory\') . \'/js/scroll/jquery.mousewheel.js\', array(\'jquery\') );
wp_enqueue_script( \'scroll_pane\', get_bloginfo(\'template_directory\') . \'/js/scroll/jquery.jscrollpane.min.js\', array(\'jquery\') );
}
add_action(\'template_redirect\', \'my_scripts\');
问题:由于当单击按钮时,页面不会刷新,并且内容通过AJAX加载到DIV中,所以我猜,加载的内容使用jQuery和其他。js文件被破坏,因为。js文件已经加载,页面上没有该内容。
我需要找到一种方法来“刷新”已加载的。js文件,以便新加载的内容不会出现损坏。还是我的做法不对?
谈到AJAX,我是个新手,因为这是我第一次使用它。我得到的是:http://www.wphardcore.com/2010/5-tips-for-using-ajax-in-wordpress/ 作为参考,但我发现我很难理解。
谢谢你的帮助!