• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Replacing Content with JS

R

ragtek

Guest
#1
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.
 

Kier

XenForo Developer
Staff member
#2
.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...
 
R

ragtek

Guest
#4
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);