Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Form_remote_Tag';s:完全回拨?_Javascript_Ruby On Rails_Ajax_Callback_Prototypejs - Fatal编程技术网

Javascript 如何在Form_remote_Tag';s:完全回拨?

Javascript 如何在Form_remote_Tag';s:完全回拨?,javascript,ruby-on-rails,ajax,callback,prototypejs,Javascript,Ruby On Rails,Ajax,Callback,Prototypejs,在Rails 2.3.3中,我想做如下工作: <% form_remote_tag :url => "/some/path/", :loading => "loadingFunction(this)", :complete => "completeFunction(this,request)" do %> “/some/path/”,:load=>“loadingFunction(this)”,:complete=>“completeFunction(this,r

在Rails 2.3.3中,我想做如下工作:

<% form_remote_tag :url => "/some/path/", :loading => "loadingFunction(this)", :complete => "completeFunction(this,request)" do %>
“/some/path/”,:load=>“loadingFunction(this)”,:complete=>“completeFunction(this,request)”do%>
基本上,我希望能够将特定的表单标记传递给:complete或:loading回调函数(以相对的方式-我不想使用ID-我希望能够获得:complete调用所对应的标记,作为:complete调用用于表单标记**的自然结果)

看。特别是,Rails为onsubmit事件生成如下代码:new Ajax.Request('/some/path/',{asynchronous:true,evalscript:true,onComplete:function(Request){completeFunction(this,Request)},onLoading:function(Request){loadingFunction(this)},参数:Form.serialize(this)};返回false;“。请注意函数调用是如何包装在新Ajax.request()中的函数(请求){}中的

所以,“this”,“jQuery(this)”,“jQuery(this).closest('.someparentelementofform')”等都不起作用


**我这样做是因为: 我在加载页面时呈现任意数量的“form_remote_tag”,用户可以触发事件,导致任意更多的“form_remote_tag”出现(每个表单中的内容相似,但每个表单中的元素数量也是任意的)。如果我在整个页面中有一个form_remote_标记,则存在几个主要问题:

  • 用户将只编辑页面的一个部分(在我当前的设计中对应于一个表单),但是页面中所有表单元素的数据都必须在请求中发送

  • 它需要某种混乱的方式来跟踪表单及其元素,为它们提供诸如“form-12”、“form-12-paramfield-13”等ID

  • 这使得允许用户提交一个表单变得非常困难:当该表单通过AJAX加载时,提交其他表单(包括触发事件导致新表单出现然后提交该表单的可能性),因为跟踪每个请求的响应数据放在何处存在问题


您是否尝试过在html选项中传递以下回调,如

:html=>{:loading=>“#{remotefunction(options)};返回false;”} 或 :html=>{:onload=>“#{remotefunction(options)};返回false;”}

可以指定的回调(按顺序):

通过为特定状态代码添加额外回调,可以进一步优化:success和:failure

最近,我在我的一个远程表单中实现了overirideonsubmit,如下所示

 <% options = {:url => {:action =>"test", :id => 1}, :with =>"Form.serialize('test_form')" }%>
 <% form_remote_tag :html=>{ :onsubmit =>"#{remote_function(options)}; return false" } do %>
{:action=>“test”,:id=>1},:with=>“Form.serialize('test_Form')”}%>
{:onsubmit=>“#{remote_函数(选项)};返回false”}do%>

您是否尝试过在html选项中传递以下回调,如

:html=>{:loading=>“#{remotefunction(options)};返回false;”} 或 :html=>{:onload=>“#{remotefunction(options)};返回false;”}

可以指定的回调(按顺序):

通过为特定状态代码添加额外回调,可以进一步优化:success和:failure

最近,我在我的一个远程表单中实现了overirideonsubmit,如下所示

 <% options = {:url => {:action =>"test", :id => 1}, :with =>"Form.serialize('test_form')" }%>
 <% form_remote_tag :html=>{ :onsubmit =>"#{remote_function(options)}; return false" } do %>
{:action=>“test”,:id=>1},:with=>“Form.serialize('test_Form')”}%>
{:onsubmit=>“#{remote_函数(选项)};返回false”}do%>

你做了什么?你做了什么?