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

Add _xftoken to XenForo.ajax function

Discussion in 'XenForo Development Discussions' started by Marcus, Nov 2, 2012.

  1. Marcus

    Marcus Well-Known Member

    This small template edit should display Watched Threads on every template it is copied. However I have to put in the xf_token, most likely at the second parameter in the XenForo.ajax request. Do you know how I could do that? Thanks !!
    PHP:
    <div id="watchedThreadsInline"></div>
    <
    script>
                 
    XenForo.ajax(
                    
    'index.php?watched/threads',
                    {},
                    function(
    ajaxData,textStatus)
                    {
                        $(
    '<li>function ajaxData,textStatus is executed</li>').xfInsert('appendTo''#watchedThreadsInline');

                        new 
    XenForo.ExtLoader(ajaxData, function()
                        {
                            $(
    ajaxData.templateHtml).appendTo('#watchedThreadsInline');
                        });
                    }
                );
    </script>[php]
     
  2. xfrocks

    xfrocks Well-Known Member

    IIRC, XenForo.ajax automatically includes csrf token in sending requests.
     
  3. Marcus

    Marcus Well-Known Member

    This is my error message:

    screenshot.png
    And this is the template edit
    PHP:
    <div id="watchedThreadsInline">
    Should be replaced by WatchedThreads
    </div>

    <
    script>
                 
    XenForo.ajax(
                    
    'index.php?watched/threads',
                    {},
                    function(
    ajaxData,textStatus)
                    {
                        $(
    '<li>function ajaxData,textStatus is executed</li>').xfInsert('appendTo''#watchedThreadsInline');

                        new 
    XenForo.ExtLoader(ajaxData, function()
                        {
                            $(
    ajaxData.templateHtml).appendTo('#watchedThreadsInline');
                        });
                    }
                );
    </script>
     

Share This Page