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

Replacing Content with JS

Discussion in 'XenForo Development Discussions' started by ragtek, Jan 19, 2011.

  1. ragtek

    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.
     
  2. Kier

    Kier XenForo Developer Staff Member

    .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...
     
  3. ragtek

    ragtek Guest

    ok, i'll try it
     
  4. ragtek

    ragtek Guest

    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);
                                                
     

Share This Page