Replacing Content with JS

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
I want to replace some code after i recive some data with ajax.

This is my code:
Code:
$link.click(function(e)
		{
			e.preventDefault();

			var $link = $(this);
                        var oldVotes = $link.data('votes');
                        var $container = $($link.data('container'));

			XenForo.ajax(this.href, {}, function(ajaxData, textStatus)
			{
                                if(ajaxData.likes){
                                    alert($container);
                                    alert(ajaxData.likes);

                                    //$container.innerHTML = '<div>test</div>';
// $container.innerHTML = 'test';
                                    $replace = ajaxData.likes;
                                    $container.xfInsert('insertBefore', $replace);
                                }
			});
		});

my 2 debugcodes
Code:
alert($container);
                                    alert(ajaxData.likes);
are showing, that the container is existing [object Object] and the likes value.

BUT the content of $container isn't replaced.
 
.xfInsert() operates on the content to be inserted - I think you have your arguments around the wrong way there.

Try this:

ajaxData.likes.xfInsert('appendTo', $container);

Note that 'appendTo' can be any jQuery function that manipulates the DOM with relation to another element, so you could do any of these:

ajaxData.likes.xfInsert('replaceAll', $container);
ajaxData.likes.xfInsert('prependTo', $container);
ajaxData.likes.xfInsert('insertBefore', $container);

etc...
 
no, it seems that this is little bit too complicated for me^^

we're using now something different, which is also working
Code:
// $(ajaxData.counter).xfInsert('insertBefore', $container));
                                            $container.text(ajaxData.counter);
 
Top Bottom