I am trying to get buddypress avatars on a network’s main site from a sub-site. The way buddypress does avatars is really involved with loops and fallbacks etc and doesn’t consist of any database calls, which would have been straightforward.
Instead I thought maybe I will create a function on my main site to output the user’s avatar and then grab it with AJAX. But the cross-domain policy is in effect and I’m having difficulty understanding how to implement JSONP to get around it.
My javascript looks like this:
$('.external-avatar').each(function(){
var user_id = $(this).data('user_id');
$.ajax({
type: 'POST',
url: vars.rootAjaxurl,
data: {
action: 'bp_cross_site_avatar',
user_id: user_id,
},
success: function(data, textStatus, XMLHttpRequest, user_id){
$(".external-avatar.user-"+user_id).attr('src', data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
// alert(errorThrown);
}
});
});
Is there a way to get a request like this to work?