监控使用AJAX XMLHtt prequest on Rails应用程序的服务器端程序 [英] Monitoring a server-side process on Rails application using AJAX XMLHttpRequest

查看:77
本文介绍了监控使用AJAX XMLHtt prequest on Rails应用程序的服务器端程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的网页下面,但不能从服务器获得响应,而它的处理

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);" %>

在fmfiles_controller.rb的create方法,然后兴高采烈地处理文件,并得到正确的结果(按照提交表单上的按钮)。如果我取消注释//警报(你好),行,我得到一个对话框,说你好每2秒......如预期。

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.

但是,服务器永远记录在文件甚至不是一个失败的尝试任何调用progress_monitor'方法。

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

如果我点击链接

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

它使调用服务器产生响应,并显示对话框,所以我承担的路线和语法和命名是一切OK了。

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.

我真的不知道为什么,这是行不通的。是不是因为2种方法在同一控制器正在通过URL叫什么名字?

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

我使用Rails 2.1.0在OS X 10.5.5开发环境和使用Safari 3.1.2

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。在此之前,从另一个<一个href="http://stackoverflow.com/questions/120201/updating-server-side-progress-on-rails-application">question,但我认为这是十分不同,值得它自己的问题。)

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

推荐答案

如果你没有看到在你的日志文件消息的呼叫'progress_monitor',那么它有可能请求永远不会被发送。

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.

试试这个:

  1. 尝试使用完整的URL,而不是为Ajax.Request的相对URL。我有问题,在某些浏览器的Ajax.Request的相对URL。

  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.

启用萤火虫或IE的开发工具栏。你应该能够看到如果调用progress_monitor作品或没有。如果有一个Java脚本错误,那么你会看到错误清楚地使用这些工具。

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.

这篇关于监控使用AJAX XMLHtt prequest on Rails应用程序的服务器端程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆