【发布时间】:2015-05-12 23:18:12
【问题描述】:
Ajax 刷新 div。但问题是它刷新了 div 内的整个页面。它就像页内页。我知道我做错了什么。
我正在开发一个 wordpress 网站(本地)。我想在节目开始后立即更改演示者的图像。 Ajax 脚本看起来不错,但不能按我想要的方式工作。所以,我需要你们的帮助............
我把我的代码放在下面。我要刷新的 div 在布局页面中,而 ajax 脚本在页脚页面中
Wordpress 模板:
<!DOCTYPE html>
<!--[if IE 8]> <html class="ie ie8" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 9]> <html class="ie ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 9]><!--> <html <?php language_attributes(); ?>> <!--<![endif]-->
<head>
<?php
/**
* Match wp_head() indent level
*/
?>
<meta charset="<?php bloginfo('charset'); ?>" />
<title><?php wp_title(''); // stay compatible with SEO plugins ?></title>
<?php if (!Bunyad::options()->no_responsive): // don't add if responsiveness disabled ?>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php endif; ?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if (Bunyad::options()->favicon): ?>
<link rel="shortcut icon" href="<?php echo esc_attr(Bunyad::options()->favicon); ?>" />
<?php endif; ?>
<?php if (Bunyad::options()->apple_icon): ?>
<link rel="apple-touch-icon-precomposed" href="<?php echo esc_attr(Bunyad::options()->apple_icon); ?>" />
<?php endif; ?>
<?php wp_head(); ?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
</head>
<body <?php body_class(); ?>>
<div class="main-wrap">
<?php
/**
* Get the partial template for top bar
*/
get_template_part('partials/header/top-bar');
?>
<div id="main-head" class="main-head">
<div class="wrap">
<?php
/**
* Get the header based on settings
*/
$header = Bunyad::options()->header_style ? Bunyad::options()->header_style : 'default';
get_template_part('partials/header/' . $header);
/**
* Setup data variables to enable or disable sticky nav functionality
*/
$attribs = array('class' => array('navigation cf', Bunyad::options()->nav_align));
if (Bunyad::options()->sticky_nav) {
$attribs['data-sticky-nav'] = 1;
// sticky navigation logo?
if (Bunyad::options()->sticky_nav_logo) {
$attribs['data-sticky-logo'] = 1;
}
}
?>
<nav <?php Bunyad::markup()->attribs('navigation', $attribs); ?>>
<div class="mobile" data-type="<?php echo Bunyad::options()->mobile_menu_type; ?>" data-search="<?php echo Bunyad::options()->mobile_nav_search; ?>">
<a href="#" class="selected">
<span class="text"><?php _e('Navigate', 'bunyad'); ?></span><span class="current"></span> <i class="hamburger fa fa-bars"></i>
</a>
</div>
<?php wp_nav_menu(array('theme_location' => 'main', 'fallback_cb' => '', 'walker' => 'Bunyad_Menu_Walker')); ?>
</nav>
</div>
</div>
<?php if (!Bunyad::options()->disable_breadcrumbs): ?>
<div class="wrap">
<?php Bunyad::core()->breadcrumbs(); ?>
</div>
<?php endif; ?>
<?php do_action('bunyad_pre_main_content'); ?>
**Layout page:**
<?php
/*
Template Name: Radio Player
*/
get_header('radio');
if (Bunyad::posts()->meta('featured_slider')):
get_template_part('partial-sliders');
endif;
?>
<div class="main wrap cf">
<div class="row">
<div class="col-8 main-content">
<?php if (have_posts()): the_post(); endif; // load the page ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('page-content'); ?>>
<?php if (Bunyad::posts()->meta('page_title') != 'no'): ?>
<header class="post-header">
<?php if (has_post_thumbnail()): ?>
<div class="featured">
<a href="<?php $url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); echo $url[0]; ?>" title="<?php the_title_attribute(); ?>">
<?php if ((!in_the_loop() && Bunyad::posts()->meta('layout_style') == 'full') OR Bunyad::core()->get_sidebar() == 'none'): // largest images - no sidebar? ?>
<?php the_post_thumbnail('main-full', array('title' => strip_tags(get_the_title()))); ?>
<?php else: ?>
<?php the_post_thumbnail('main-slider', array('title' => strip_tags(get_the_title()))); ?>
<?php endif; ?>
</a>
</div>
<?php endif; ?>
</header><!-- .post-header -->
<?php endif; ?>
<div class="refreshMe">
<?php Bunyad::posts()->the_content(); ?>
</div>
</div>
</div> <!-- .row -->
</div> <!-- .main -->
</div>
<?php get_footer('radio'); ?>
**i put my refresh div on the layout page with class name "refreshMe
Footer.php**
<?php do_action('bunyad_post_main_content'); ?>
<footer class="main-footer">
<p>
Copyright © Babylon Radio 2015
</p>
</footer>
</div> <!-- .main-wrap -->
<?php wp_enqueue_script("jquery"); ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.timers-1.0.0.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
var j = jQuery.noConflict();
j(document).ready(function()
{
j(".refreshMe").everyTime(10000,function(i){
j.ajax({
cache: false,
success: function(html){
j(".refreshMe").html(html);
}
})
})
});
j('.refreshMe').css({color:"red"});
});
</script>
<?php wp_footer(); ?>
</body>
</html>
**and my ajax script is in the footer page.**
Help me out with this
【问题讨论】:
-
google wordpress jQuery ajax 教程,您的 ajax 函数有很多问题(缺少 url、缺少操作、未向服务器传递任何内容)。您也没有显示处理 ajax 提交的 php 函数。所以目前还没有多少人可以帮助你。
标签: javascript php ajax wordpress