ajax请求后Wordpress工具提示不可见
在Wordpress中导入ajax后,我对工具提示有问题 插件是: 该插件使用:jquerypowertip 工具提示不可见 custom.jsajax请求后Wordpress工具提示不可见,ajax,wordpress,tooltip,Ajax,Wordpress,Tooltip,在Wordpress中导入ajax后,我对工具提示有问题 插件是: 该插件使用:jquerypowertip 工具提示不可见 custom.js (function($){ 'use strict'; $(function (e) { $('.get_project').on( 'click', function(e) { e.preventDefault(); var postid = $(this).att
(function($){
'use strict';
$(function (e) {
$('.get_project').on( 'click', function(e) {
e.preventDefault();
var postid = $(this).attr('data-postid');
console.log(postid);
$.ajax({
type: "POST",
url: my_ajax_object.ajax_url,
data: {
action: 'my_load_ajax_content',
postid: postid,
}
}).done(function (data) {
$('.TARGETDIV').html(data).trigger('post-load');
});
});
});
})(jQuery);
functions.php
function my_load_ajax_content () {
$pid = intval($_POST['postid']);
$the_query = new WP_Query(array('p' => $pid));
if ($the_query->have_posts() && $pid > 0) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$data = '
<div class="post-container">
<div id="project-content">
<h2 class="custom-h2">' . get_the_title() . '</h2>
<!-- <div class="entry-content">'. get_the_content() . '</div> -->
<div class="entry-content">' . do_shortcode(get_post_field('post_content', $pid)). '</div>
</div>
</div>
';
}
}
else {
$data = '<div id="postdata">'.__('Not found', THEME_NAME).'</div>';
}
wp_reset_postdata();
echo '<div id="postdata">'. $data .'</div>';
die();
}
add_action ( 'wp_ajax_nopriv_my_load_ajax_content', 'my_load_ajax_content' );
add_action ( 'wp_ajax_my_load_ajax_content', 'my_load_ajax_content' );
function my_enqueue() {
wp_register_script( 'ajax-script', get_template_directory_uri() . '/js/custom.js', array('jquery') );
wp_localize_script( 'ajax-script', 'my_ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
);
wp_enqueue_script( 'ajax-script' );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue' );
函数my\u load\u ajax\u content(){
$pid=intval($_POST['postid']);
$the_query=new WP_query(数组('p'=>$pid));
if($the_query->have_posts()&&$pid>0){
while($the\u query->have\u posts()){
$the_query->the_post();
$data=
“.获取标题()
“.do_短代码(获取_post_字段('post_content',$pid))。”
';
}
}
否则{
$data=''。uuuu('未找到',主题名称)。'';
}
wp_reset_postdata();
回显“.$data.”;
模具();
}
添加动作('wp_ajax_nopriv_my_load_ajax_content'、'my_load_ajax_content');
添加动作(“wp\u ajax\u我的加载\u ajax\u内容”,“我的加载\u ajax\u内容”);
函数my_enqueue(){
wp_register_script('ajax script',get_template_directory_uri()。/js/custom.js',array('jquery');
wp_本地化_脚本('ajax脚本','my_ajax_对象',
数组('ajax\u url'=>admin\u url('admin ajax.php'))
);
wp_排队_脚本(“ajax脚本”);
}
添加_操作('wp_排队_脚本','my_排队');
看起来数据正在返回。工具提示不可见
前
工具提示文本
请帮忙我今天遇到了同样的问题,四处寻找解决办法。从ajax返回时,似乎所有的点数据都未绑定,只在下一个
$(document).ready()上反弹
您可以通过将其放入ajax回调的成功部分来强制重新启动:
$('body').html($('body').html());
当我在弹出窗口中查看输出时,这对我不起作用,因此我必须通过函数调用maps.points.js
中的代码
将其放在AJAX调用的成功部分:
success: function(response){
// refresh the popup with response data ...
reload_map_data();
}
这是函数调用:
function reload_map_data(){
$('.ihotspot_hastooltop').each(function(){
$(this).data('powertip', function() {
var htmlThis = $(this).parents('.ihotspot_tooltop_html').attr('data-html');
return htmlThis;
});
var thisPlace = $(this).parents('.ihotspot_tooltop_html').data('placement');
$(this).powerTip({
placement: thisPlace,
smartPlacement: true,
mouseOnToPopup: true,
}).on({
powerTipClose: function() {
$('#powerTip').html('');
}
});;
$('body').on('click','.close_ihp',function () {
$.powerTip.hide();
});
})
}
function reload_map_data(){
$('.ihotspot_hastooltop').each(function(){
$(this).data('powertip', function() {
var htmlThis = $(this).parents('.ihotspot_tooltop_html').attr('data-html');
return htmlThis;
});
var thisPlace = $(this).parents('.ihotspot_tooltop_html').data('placement');
$(this).powerTip({
placement: thisPlace,
smartPlacement: true,
mouseOnToPopup: true,
}).on({
powerTipClose: function() {
$('#powerTip').html('');
}
});;
$('body').on('click','.close_ihp',function () {
$.powerTip.hide();
});
})
}