In one of my web application I have a "Mark as Favorite icon". So when some one clicks on this button. It disappears and an ajax request is called
jQuery('.favr').click(function() {
var user_IDs = jQuery(this).attr('id');
var current_IDs = '<?php echo $cui ?>';
jQuery.ajax({
url: '<?php bloginfo('url') ?>/',
type: 'POST',
data: {'ajaxreturn': '102', 'logedid': current_IDs,'ids':user_IDs},
success: function(result) {
jQuery('.favh').html(result);
}
});
});
which inserts the user id in database and returns a response with an icon "Remove Favorite". All this is working OK. Ajax response is
<i data-tooltip="" data-selector="tooltip0D27OP" title="Remove Favorite" class="has-tip tip-left radius icon-heart-empty orange favr-'. $userID .' id='. $userID.' ></i>
I can see this response in my google chrome Network tab. But the problem is this response doesn't display in the the div element with class .favh and remains empty. Please tell me where I am wrong. I am working in wordpress that's why I used
url: '<?php bloginfo('url') ?>/',
Here is my php code, that ajax calls
add_action('init','my_ajaxreturn_102');
function my_ajaxreturn_102(){
if ($_POST['ajaxreturn'] == 102) {
$userID = $_POST['ids'];
$loggedID = $_POST['logedid'];
$rem_array = json_decode(get_user_meta($loggedID, 'meta_favorite', true), true);
$fav_array = array_unique($rem_array);
$searched_item = array_search($userID,$fav_array);
unset($fav_array[$searched_item]);
update_user_meta( $loggedID, 'meta_favorite', json_encode($fav_array));
echo '<i data-tooltip="" data-selector="tooltip0D27OP" title="Remove Favorite" class="has-tip tip-left radius icon-heart-empty orange favr-'. $userID .' id='. $userID.' ></i>';
exit;
}
}
All this code is working fine, sending response
<i data-tooltip="" data-selector="tooltip0D27OP" title="Remove Favorite" class="has-tip tip-left radius icon-heart-empty orange favr-'. $userID .' id='. $userID.' ></i>
but only problem is not displaying this response.