• 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...

Jaxel

Well-known member
#1
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?
 

Jeremy

Well-known member
#2
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.
 
R

ragtek

Guest
#5
Just check the xenforo.js ;)
Code:
        /**
         * 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)
 

Jaxel

Well-known member
#6
Well I figured out how to POST the messages via ajax... I just haven't figured out how to update the message list...

Code:
	<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" />
			</div>
		</div>
	</form>

	<ol class="messageSimpleList" id="ProfilePostList">
		<xen:if is="{$comments}">
			<xen:foreach loop="$comments" value="$comment">
				<xen:include template="EWRmedio_Comment" />
			</xen:foreach>
		<xen:else />
			<li id="NoProfilePosts">{xen:phrase there_no_messages_on_xs_profile_yet, 'name={$media.media_title}'}</li>
		</xen:if>
	</ol>
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:
Code:
Unable to request validation for field "message" due to lack of fieldValidatorUrl in form tag
 

Jaxel

Well-known member
#7
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.