Poseidon's punishment. The adventures of Ajax
I’ve been finishing this rather large, heavy on the ajax rails site. And been nagged by this persistent untraceable bug for the last while.
So I went out for most excellent Thai food. When I came back refreshed, the solution was apparent. It turns out to be a combination of a few things. First off, the bug only appears in IE windows, not Firefox, not Mac. Damn majority of browser users. Hmph.
Anyway. Here is a tip.
When updating a page using inline RJS templates – or – Ajax dynamicly setting form fields from an auto complete use this:
def get_agent_info
# by converting the :id to an integer I strip out the letters. if the text_field returns "100 joel jensen" the id becomes 100
@agent = Agent.find(params[:id].to_i)
# this section does an inline .rjs template
# I am sending back javascript that will update the required fields to the new values.
if request.xhr?
render :update do |page|
page << "document.getElementById('appointment_office_phone').value = '#{number_to_phone(@agent.office.office_phone, :area_code => true)}'"
page << "document.getElementById('appointment_showing_agent_id').value = '#{@agent.id}'"
page << "document.getElementById('appointment_showingagent').value = '#{@agent.fullname}'"
end
else
render :text => 'javascript update failed.'
end
end
not this:
def get_agent_info
# by converting the :id to an integer I strip out the letters. if the text_field returns "100 joel jensen" the id becomes 100
@agent = Agent.find(params[:id].to_i)
# this section does an inline .rjs template
# I am sending back javascript that will update the required fields to the new values.
if request.xhr?
render :update do |page|
page << "appointment_office_phone'.value = '#{number_to_phone(@agent.office.office_phone, :area_code => true)}'"
page << "appointment_showing_agent_id'.value = '#{@agent.id}'"
page << "appointment_showingagent'.value = '#{@agent.fullname}'"
end
else
render :text => 'javascript update failed.'
end
end
Also– lighttpd will compress javascript files. Great for deployment. However IE will cache these zip files, and prefer them to newer js textfiles. Use webrick for testing on ie or turn off mod_compress on lighty.
Why is this a problem?
I had to upgrade the prototype js files to get the dynamic table rendering ajax stuff to work, cached old versions of prototype were lingering around and messing things up.
I should relax more.