Ajax commenting - PLEASE HELP!

I’m trying to post comments using Ajax. It seems that I have an
infinite loop somewhere, because it hangs on the return from the Ajax
call. The comment does get saved to the DB, but I have to refresh the
page for it to show.

The reason I know it’s some sort of infinite loop, is because I’m
showing a “loading.gif” image, and it never goes away. Plus, if the
comment doesn’t save, I’m returning an error message. I’ve posted the
code for the VIEW and CONTROLLER below. Please HELP!

#VIEW

Have something to say?
<%= form_remote_tag( :url => {:controller => 'journal', :action => 'comments', :id => entry.id}, :update => {:success => "new-comment"}, :loading => "Element.show('loading');", :success => "Element.hide('loading');", :complete => "clearText();", :position => "bottom" ) %>
 <p>Name:<br/>
 <%= text_field "comment", "name", :size => "20" %></p>

 <p>Remark:<br/>
 <%= text_area "comment", "entry", :rows => "7", :cols => "35"%></p>

 <p><input type="submit" name="submit" id="form-submit-button" 

value=“Post Remark” class=“btn” />

<%= end_form_tag %>

#CONTROLLER
def comments
post = Post.find(params[:id])
@comment = Comment.new(params[:comment])
post.comments << @comment
post.save
if @comment.save then
@comment_count = Comment.count(“post_id=#{params[:id]}”)
render_without_layout
else
render :text => “Error saving comment”
end
end

ryan wrote:

I’m trying to post comments using Ajax. It seems that I have an
infinite loop somewhere, because it hangs on the return from the Ajax
call. The comment does get saved to the DB, but I have to refresh the
page for it to show.

My guess is that your getting hung up on a javascript syntax error. The
loading gif never goes away because the javascript hits an error half
way and never finishes executing.

First, I recommend that you use the firebug extension for firefox, as it
lets you inpect the query, and response of AJAX calls super easily.

Second, turn on RJS error reporting by adding the following to
config/environments/development.rb

RJS Error reporting

config.action_view.debug_rjs = true

That should make anything that goes wrong popup in an alert box.