【发布时间】:2020-10-11 09:17:21
【问题描述】:
网站上有一个按钮,当您单击该按钮时,会加载新帖子。在桌面上一切正常,但在手机上就坏了。
XHR failed loading: POST "https://test-5.vbbn.in/wp-admin/admin-ajax.php". send @ jquery.js?ver=1.12.4-wp:4 ajax @ jquery.js?ver=1.12.4-wp:4 n. @ jquery.js?ver=1.12.4-wp:4 (anonymous) @ (index):1732 dispatch @ jquery.js?ver=1.12.4-wp:3 r.handle @ jquery.js?ver=1.12.4-wp:3
add_action( 'wp_footer', 'my_action_javascript' );
function my_action_javascript() { ?>
<script>
jQuery(document).ready(function($) {
var page = 2;
var post_count = jQuery('#posts').data('count');
var ajaxurl = "<?php echo admin_url('admin-ajax.php');?>"
jQuery('#load_more').click(function () {
var data = {
'action': 'my_action',
'page': page
};
jQuery.post(ajaxurl, data, function(response) {
jQuery('#posts').append(response);
if (post_count == page){
jQuery('#load_more').hide();
}
page++;
});
});
});
</script> <?php
}
add_action( 'wp_ajax_my_action', 'my_action' );
function my_action() {
$args = array(
'post_type' => 'post',
'category_name'=> 'nouvelles',
'paged' => $_POST['page'],
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
尝试添加e.preventDefault,以避免重启不写POST然后将事件传递给函数,但它表明e.preventDefault不是一个函数。
网站 - https://test-5.vbbn.in/ 希望得到任何帮助。谢谢
【问题讨论】:
标签: javascript php jquery ajax wordpress