views:

36

answers:

0

I'm have a Rails 3 app that uses Prototype.

I create a form with:

=form_for :appt, :url => { :controller => "appts", :action => 'create' }, :html => { :id => "apptform" }, :remote => true do |f|

That controller returns some json:

render :json => @appt

Some javascript waits til the dom is loaded, then sets some observers:

document.observe('dom:loaded', function() {
    initForm();
}); 

function initForm() {

    Event.observe('apptform', 'ajax:success', function(event){ 
        onFormSuccess(event);
    });
}

function onFormSuccess(result) {
    alert(result.readyState)
}

But when the form is submitted, and onFormSuccess is called, the event seems to be lost. result.responseText is undefined. I tried other properties of 'result' too with no luck. Is there some reason the event is getting lost? result.responseText should contain the json that is returned from the controller. The controller logs the value of the json before it returns it and I can tell that it's valid.