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

AJAX in XenForo... oh boy...

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 9, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    Ajax has always confused me... its why I always used vBulletin's built in YUI Ajax processor to handle all my Ajax queries. It worked, without any of that prototyping and what not that confuses me... Now I see that XenForo's Ajax seems to be built on jQuery... supposedly that makes it even easier...

    But I'm looking through the built in XenForo JS files and I am confused... All the javascript in XenForo seems to be pretty selfcontained and automatic... I just want to have a simple comment form using message_simple.css and quick_reply_profile.js...

    Any ideas?
  2. Jeremy

    Jeremy Well-Known Member

    I know you can use jQuery.ajax() and it should work. :) I use it when I do AJAX because I haven't figured out how to accomplish this.
  3. Jaxel

    Jaxel Well-Known Member

    Yeah... but I want to do things right...
  4. Jeremy

    Jeremy Well-Known Member

    If they are doing it via AJAX, I am almost sure jQuery.ajax() is how its being done.
  5. ragtek

    ragtek Guest

    Just check the xenforo.js ;)
             * Wraps around jQuery's own $.ajax function, with our own defaults provided.
             * Will submit via POST and expect JSON back by default.
             * Server errors will be handled using XenForo.handleServerError
             * @param string URL to load
             * @param object Data to pass
             * @param function Success callback function
             * @param object Additional options to override or extend defaults
             * @return XMLHttpRequest
            ajax: function(url, data, success, options)
    CyberAP likes this.
  6. Jaxel

    Jaxel Well-Known Member

    Well I figured out how to POST the messages via ajax... I just haven't figured out how to update the message list...

    	<form action="{xen:link 'full:media/post', $media}" method="post" style="margin: 0px;"
    		class="messageSimple AutoValidator primaryContent" id="ProfilePoster" data-optInOut="optIn">
    		<xen:avatar user="$visitor" size="s" />
    		<div class="messageInfo">
    			<textarea name="message" class="textCtrl Elastic" placeholder="{xen:phrase update_your_status}..." rows="3" cols="50"></textarea>
    			<div class="submitUnit">
    				<input type="hidden" name="media_id" value="{$media.media_id}" />
    				<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
    				<input type="submit" class="button primary" value="{xen:phrase post}" accesskey="s" />
    	<ol class="messageSimpleList" id="ProfilePostList">
    		<xen:if is="{$comments}">
    			<xen:foreach loop="$comments" value="$comment">
    				<xen:include template="EWRmedio_Comment" />
    		<xen:else />
    			<li id="NoProfilePosts">{xen:phrase there_no_messages_on_xs_profile_yet, 'name={$media.media_title}'}</li>
    By looking through quick_reply_profile.js... it looks like it should prepend the new comment to ProfilePostList... but it doesn't do that...

    I get the following warning too:
    Unable to request validation for field "message" due to lack of fieldValidatorUrl in form tag
  7. Jaxel

    Jaxel Well-Known Member

    Oh well... I'll just leave ajax out of my mods until there is further documentation... because I can't figure this out at all.
  8. Kier

    Kier XenForo Developer Staff Member

    I will attempt to do a tutorial covering XenForo.ajax() and form.AutoValidator over the weekend if time allows.
    pjfry, CurveGotti, Rene and 1 other person like this.
  9. Jaxel

    Jaxel Well-Known Member

    Thanks Kier...

Share This Page