AJAX in XenForo... oh boy...


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?
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.
If they are doing it via AJAX, I am almost sure jQuery.ajax() is how its being done.
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)
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
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.
Top Bottom