views:

691

answers:

1

I'm using the following in the web page but can't get a response from the server while it's processing

<script type="text/javascript">
<!--
   function updateProgress() {
      //alert('Hello');
      new Ajax.Request('/fmfiles/progress_monitor', {
         parameters: 'authenticity_token=' + encodeURIComponent(AUTH_TOKEN),
         onSuccess: function(response) {
            alert(response.responseText);
            fillProgress('progressBar',response.responseText);
         }
      });
   }
//-->
</script>

<% form_for( :fmfile, :url => '/fmfiles', :html => { :method => :post, :name => 'Form_Import', :enctype => 'multipart/form-data' } ) do |f| %>
...
<%= f.file_field :document, :accept => 'text/xml', :name => 'fmfile_document' %>
<%= submit_tag 'Import', :onClick => "setInterval('updateProgress()', 2000);" %>

The 'create' method in fmfiles_controller.rb then happily processes the file and gets the right results (as per the submit button on the form). If I uncomment the '//alert('Hello')' line I get a dialog saying Hello every 2 seconds ... as expected.

However, the server never logs any call to 'progress_monitor' method in 'files' not even a failed attempt.

If I click the link

<a href="#" onclick="updateProgress();">Run</a>

it makes a call to the server, gets a response and displays the dialog, so I assume the routes and syntax and naming is all OK.

I really don't know why this isn't working. Is it because 2 methods in the same controller are being called via URLs?

I'm using Rails 2.1.0 in a development environment on OS X 10.5.5 and using Safari 3.1.2

(N.B. This follows on from another question, but I think it's sufficiently different to merit its own question.)

+2  A: 

If you are not seeing messages in your log file for the call to 'progress_monitor' then it is possible that the request is never being sent.

Try this:

  1. Try using the full URL instead of the relative URL for the Ajax.Request. I have had problems with relative URLs on some browsers with the Ajax.Request.

  2. Enable Firebug or the IE Developer Toolbar. You should be able to see if the call to progress_monitor works or not. If there is a java script error then you will see the error clearly using these tools.

Ken
1. I tried that but the URL uses GET, I need to use POST for the call to the method, so I just get an Action Controller Exception
Matt Haughton
2. In installing Firebug (ashamed to say I haven't been using it) I tried the request in Firefox, it works! I think it's a Safari bug, I'll google it and add an answer if I find anything.
Matt Haughton