Javascript 函数在Colorbox中不工作
在我的网站上,我使用的是colorbox 当您单击主屏幕上的缩略图时,我使用此脚本打开我的颜色框Javascript 函数在Colorbox中不工作,javascript,jquery,ajax,colorbox,Javascript,Jquery,Ajax,Colorbox,在我的网站上,我使用的是colorbox 当您单击主屏幕上的缩略图时,我使用此脚本打开我的颜色框 jQuery.ajax({ type: 'POST', url: 'http://motiongraphicscollective.com/wp-admin/admin-ajax.php', data: { action: 'myAjax', blog_id: blog, sin
jQuery.ajax({
type: 'POST',
url: 'http://motiongraphicscollective.com/wp-admin/admin-ajax.php',
data: {
action: 'myAjax',
blog_id: blog,
single_id: single,
},
beforeSend:function(data){ // Are not working with dataType:'jsonp'
$("#"+single+"").find('.project-title').html('<img src="http://motiongraphicscollective.com/wp-content/themes/parallelus-salutation/assets/images/bp-ajax-loader.gif">');
},
success: function(data, textStatus, XMLHttpRequest){
$("#single-content").html('');
$("#single-content").append(data);
$(".single_popup").click();
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
$(document).bind('cbox_closed', function(){
$("#"+single+"").find('.project-title').html(title);
});
jQuery.ajax({
键入:“POST”,
网址:'http://motiongraphicscollective.com/wp-admin/admin-ajax.php',
数据:{
动作:“myAjax”,
blog_id:blog,
单号:单号,
},
beforeSend:函数(数据){//未使用数据类型:“jsonp”
$(“#”+单个+”).find('.project title').html('');
},
成功:函数(数据、textStatus、XMLHttpRequest){
$(“#单一内容”).html(“”);
$(“#单一内容”)。追加(数据);
$(“.single_popup”)。单击();
},
错误:函数(MLHttpRequest、textStatus、errorshown){
警报(错误抛出);
}
});
$(document).bind('cbox_closed',function(){
$(“#”+单个+”).find('.project title').html(title);
});
正如您所看到的,我使用Ajax打开我的配色箱。函数myAjax将填充div#单个内容
function myAjax(){
global $bp;
//get data from our ajax() call
$blog_id = $_POST['blog_id'];
$single_id = $_POST['single_id'];
switch_to_blog($blog_id);
$post_x = get_post($single_id);
//Author Media
$author = $post_x->post_author;
$author_firstname = get_the_author_meta('first_name',$author);
$author_lastname = get_the_author_meta('last_name',$author);
$author_proffesion = get_user_meta( $author,'user_profession', true );
if(!$author_firstname){
$author_name = get_the_author_meta('user_login',$author);
} else {
$author_name = $author_firstname . '</br>' . $author_lastname;
}
if ( is_user_logged_in() && !bp_is_my_profile() ){
$metion = '<a href="' . bp_get_send_public_message_link() . '" title="Mention this user in a new public message, this will send the user a notification to get their attention.">@ mention</a>';
}
$posttext = $post_x->post_content;
$regular_expression = '~<img [^\>]*\ />~';
$only_post_text = preg_replace( $regular_expression, '' , $posttext);
$output = '<div id="single-video">' . videoBox($single_id) . '</div>';
$output .= '<div id="single-middle">'.
'<div id="single-sidebar">'.
'<div id="single-sidebar-inner">'.
'<div id="single-avatar">' . bp_core_fetch_avatar( array( 'item_id' => $post_x->post_author, 'type' => 'full' ) ) . '</div>'.
'<div id="single-author"><h3 class="entry-title">' . $author_name . '</h3></div>'.
'<div id="single-proffession" class="proffesion">' . $author_proffesion .'</div>'.
'<div id="single-follow"></div>'.
'<div id="single-portfolio"><a class="btn" href="' . bp_core_get_user_domain($author) . '" title="to author profile">View more projects</a> </div>'.
'</div>'.
'</div>'.
'<div id="single-main">'.
'<div class="voting-box">'.
'<div id="up">'.
wdpv_get_vote_up_ms(true, $blog_id, $single_id) .
'</div>'.
'<div id="results">'.
wdpv_get_vote_result_ms(false, $blog_id, $single_id). '<span>Thumbs up</span>'.
'</div>'.
'</div>'.
'<div id="single-title">' . $post_x->post_title . '</div>'.
'<div id="single-text"><p>' . $only_post_text . '</p></div>'.
'</div>'.
'</div>';
restore_current_blog();
// Return String
die($output);
函数myAjax(){
全球$bp;
//从ajax()调用获取数据
$blog\u id=$\u POST['blog\u id'];
$single_id=$_POST['single_id'];
切换到博客($blog\u id);
$post\u x=获取\u post($single\u id);
//作者媒体
$author=$post\u x->post\u author;
$author\u firstname=获取作者元($author);
$author\u lastname=获取作者元($author);
$author\u proffision=get\u user\u meta($author,'user\u proffision',true);
如果(!$author\u firstname){
$author\u name=获取作者元('user\u login',$author);
}否则{
$author\u name=$author\u firstname.。$author\u lastname;
}
如果(是用户登录的()&&!bp是我的配置文件()){
$metion='';
}
$posttext=$post\u x->post\u内容;
$regular\u expression='~]*\/>~';
$only_post_text=preg_replace($regular_expression,,$posttext);
$output=''.videoBox($single_id)。'';
$output.=''。
''.
''.
''.bp_core_fetch_avatar(数组('item_id'=>$post_x->post_author,'type'=>'full')。''。
“.$author_name.”。
“.$author\u profesion.”。
''.
' '.
''.
''.
''.
''.
''.
wdpv_get_vote_up_ms(true,$blog_id,$single_id)。
''.
''.
wdpv_get_vote_result_ms(false,$blog_id,$single_id)。“竖起大拇指”。
''.
''.
'.$post\u x->post\u title'。
“”。$only_post_text.”。
''.
'';
还原当前日志();
//返回字符串
模具(产量);
}
也许不是Ajax最好的一部分,但它很有效
但并不是所有的功能都有效,竖起大拇指按钮不起作用。这是一个Wordpress插件,也可以与Ajax一起使用。(此处为工作示例)
如何使竖起的大拇指在colorbox中工作?这些元素是动态添加的,因此需要将事件添加到ajax函数的
success
元素中。如果您不重新绑定它,那么将永远不会有对当前绑定事件的任何请求。如何将其重新绑定到colorbox?